当前位置:网站首页>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}$')
边栏推荐
- Transformer interprets and predicts instance records in detail
- 自营商城提高用户留存小技巧,商城对接小游戏分享
- Cloud Computing Basics - Study Notes
- js判断文字是否超过区域
- 初识网页与浏览器
- Problems encountered in installing Yolo3 target detection module in Autoware
- The future of cloud gaming
- selenium模块的操作之拉钩
- Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
- transport layer protocol
猜你喜欢

The cocos interview answers you are looking for are all here!

亚马逊美国站:马术头盔CPC认证标准要求

selenium学习

The future of cloud gaming

LaTeX image captioning text column automatic line wrapping

GetEnumerator method and MoveNext and Reset methods in Unity

Detailed explanation of the construction process of Nacos cluster

sql server duplicate values are counted after

花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口

Late night drinking, 50 classic SQL questions, really fragrant~
随机推荐
农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1
NACOS Configuration Center Settings Profile
The size of the screen adaptation
Quick Start to Drools Rule Engine (1)
link 和@improt的区别
LaTeX 图片加标题 文本分栏自动换行
ALC experiment
transport layer protocol
numpy.random usage documentation
The 25 best free games on mobile in 2020
Programmers should understand I/O this way
Media query, rem mobile terminal adaptation
Network Troubleshooting Basics - Study Notes
Error correction notes for the book Image Processing, Analysis and Machine Vision
超简单的白鹭egret项目添加图片详细教程
自营商城提高用户留存小技巧,商城对接小游戏分享
DevOps-了解学习
Writing OpenCV in VSCode
【FAQ】什么是 Canon CCAPI
DevOps - Understanding Learning