当前位置:网站首页>Matplotlib plotting notes
Matplotlib plotting notes
2022-08-05 06:45:00 【ProfSnail】
使用Python中的Matplotlib绘图,There are some functions that are not fully remembered,Every time you have to go online to find the corresponding code usage,Take this article as a note,记录常用、Uncommon usage.
官方文档地址:https://matplotlib.org/stable/api/axes_api.html
坐标轴
Axis label density
MultipleLocator(1)表示间距为1.
from matplotlib import ticker
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
不显示坐标轴
All borders will be hidden at once.
plt.axis('off')
The scale of the horizontal and vertical axes
Let the ratio of the horizontal and vertical axes be 1:1.
plt.gca().set_aspect(1)
坐标轴范围
It is used in the normal single-image situationplt.xlim(xmin,xmax).Use in multi-image situationsax.set(xlim=(xmin, xmax),ylim=(ymin,ymax)).
# Generally used for single image
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
# Multi-map case
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
# or single image use
plt.gca().set(xlim=(xmin, xmax), ylim=(ymin, ymax))
子图
生成子图
生成子图,plt.subplots(行数,列数),返回的axesis a two-dimensional index structure.
fig, axes = plt.subplots(nrows=2, ncols=2)
Flatten a two-dimensional index structure into a one-dimensional index structure,axes.flatten()
for i, ax in enumerate(axes.flatten()):
ax.plot(x, y)
子图标题
使用ax.set_title(‘title’)The name of the marker subgraph,此时,The title is usually at the top of the figure.
ax.set_title('title')
To make the title at the bottom of the figure,使用y=-0.2,Defines the position of the title.
ax.set_title('title', y=-0.2)
fontsize=15,调整字体大小.
ax.set_title('title', y=-0.2, fontsize=15)
子图间距
通过plt.subplots_adjust进行调整,参数里面的top, left, right, rightIt corresponds to the bottom left corner of the image as the origin,The position ratio of the top, bottom, left, and right corners,取值为0-1.wspace和hspaceControls the vertical and horizontal spacing between subplots.
plt.subplots_adjust(left, bottom, right, top, wspace, hspace)
Sets the display range of the subplot axes
如果使用plt.xlim(xmin, xmax)的方式,在迭代过程中,This range limit only applies to the last subgraph,The correct way is to use for each subplotax.set(xlim=(xmin,xmax))的方法.
参见:https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.axis.html
fig, axes = plt.subplots(2, 3)
for i, ax in enumerate(axes.flatten()):
ax.set(xlim=(xmin, xmax), ylim=(ymin,ymax))
绘制
绘制箭头
由xytextthe coordinates point toxy的坐标.
plt.gca().annotate("", xy=(0, 2.5), xytext=(0, -1.2),
arrowprops=dict(arrowstyle="->"))
Write text on the image
使用$$之后,与LaTeX的使用方法一样.
plt.text(x=1, y=2, s=r'$\hat{\beta}$')
边栏推荐
- Mina disconnects and reconnects
- cs231n学习记录
- 单片机期末复习大题
- 获取预训练模型的网络输入尺寸
- js判断文字是否超过区域
- Some basic method records of commonly used languages in LeetCode
- scikit-image图像处理笔记
- GetEnumerator method and MoveNext and Reset methods in Unity
- VLAN is introduced with the experiment
- Dry!Teach you to use industrial raspberries pie combining CODESYS configuration EtherCAT master station
猜你喜欢
随机推荐
花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口
前置++和后置++的区别
vscode笔记
【FAQ】CCAPI兼容EOS相机列表(2022年8月 更新)
单片机期末复习大题
Nacos配置服务的源码解析(全)
HelloWorld
System basics - study notes (some command records)
浏览器兼容汇总
input detailed file upload
Successful indie developers deal with failure & imposters
H5开发调试-Fiddler手机抓包
Cocos Creator Mini Game Case "Stick Soldier"
自营商城提高用户留存小技巧,商城对接小游戏分享
深入分析若依数据权限@datascope (注解+AOP+动态sql拼接) 【循序渐进,附分析过程】
人人AI(吴恩达系列)
记录vue-页面缓存问题
selenium学习
The future of cloud gaming
wc, grep, tar, vi/vim