当前位置:网站首页>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}$')
边栏推荐
- 文件内音频的时长统计并生成csv文件
- 系统基础-学习笔记(一些命令记录)
- LeetCode刷题记录(2)
- LeetCode practice and self-comprehension record (1)
- Passing parameters in multiple threads
- 大小屏适配
- Billions of IT operations in the market, the product by strength to speak
- One-arm routing experiment and three-layer switch experiment
- VRRP overview and experiment
- D41_buffer pool
猜你喜欢
随机推荐
Dry!Teach you to use industrial raspberries pie combining CODESYS configuration EtherCAT master station
淘宝客APP带自营商城本地生活CPS外卖优惠电影票话费更新渠道跟单生活特权V3
Transformer详细解读与预测实例记录
Four ways to obtain Class objects through reflection
多线程之传递参数
Error correction notes for the book Image Processing, Analysis and Machine Vision
D39_Eulerian Angles and Quaternions
Detailed explanation of the construction process of Nacos cluster
config.js related configuration summary
Media query, rem mobile terminal adaptation
网络排错基础-学习笔记
scikit-image image processing notes
selenium学习
The future of cloud gaming
单片机期末复习大题
花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口
js判断文字是否超过区域
UI刘海屏适配方式
人人AI(吴恩达系列)
numpy.random使用文档









