一些有用的py库

python库

1.request

快速入门 — 请求 2.32.3 文档 (requests.readthedocs.io)

发送get请求

1
2
3
4
5
6
7
8
9
requests.get(url, params=None, **kwargs)
'''Sends a GET request.

:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response'''
常见**kwargs参数 类型 说明
header dict
cookies dict或 RequestsCookieJar 对象
auth tuple或 requests.auth.HTTPBasicAuth 对象 作用:用于 HTTP 基本认证。
allow_redirects bool 作用:是否允许自动重定向。 默认值True
timeout int/double/tuple 作用:设置请求超时时间(以秒为单位),可以是连接超时,也可以是读取超时,或者两者的元组。

2.json

JSON

3.plotly

用 Python plotly express

简单使用

1
2
3
from plotly import express as px
fig = px.bar(x=[],y=[],title="",label={'x':'','y':''})
fig.show()

定制外观

设置图片样式

1
fig.update_layout(title_font_size= ,xaxis_title_font_size= ,yaxis_title_font_size= )

添加工具提示

1
2
3
4
5
6
7
8
9
hover_texts = []

...
hover_text = f'{python变量}<br/>{python变量}'
#f'' 使用HTML语法,当要插入python变量时用{python变量}
#因此可以使用<a><a/>标签插入链接,以此类推至其他标签
hover_texts.append(hover_text)

fig = px.bar(... , hover_name = hover_text)

定制标记颜色

1
2
3
fig.update_traces(marker_color='SteelBlue',marker_opacicy=0.6)
#trace指的是图形上的数据,前缀为marker_的变量都会影响标记
#marker_opacicy控制不透明度,范围0.0~1.0,0.0为完全透明

一些有用的py库
https://fiy-pc.github.io/2024/10/29/一些有用的py库/
作者
FIY-pc
发布于
2024年10月29日
许可协议