学习使用Python作图过程中的笔记,主要记录一些自己没见过的,要注意的地方,主要跟着matplotlib官网教程的节奏!
1. Annotations (图中注释):
from 官网 “an arrow pointing to?xy, to a piece of text at?xytext”
Example1:('local max', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(facecolor='black', shrink=0.05))?
shrink:将尖端和底部从带注释的点和文本移开一些百分比
用 annotate()实现,xy指定箭头起始位置,xytext指定注释文字位置,arrowprops设置箭头格式。
除了例子中的方式之外,还有多种设置 (注释文本的位置) 的方法,见下表:
argument | coordinate system |
---|
'figure points' | points from the lower left corner of the figure | 'figure pixels' | pixels from the lower left corner of the figure | 'figure fraction' | (0, 0) is lower left of figure and (1, 1) is upper right | 'axes points' | points from lower left corner of axes | 'axes pixels' | pixels from lower left corner of axes | 'axes fraction' | (0, 0) is lower left of axes and (1, 1) is upper right | 'data' | use the axes data coordinate system |
传递:bb = t.get_bbox_patch()
bbox_props = dict(boxstyle="larrow", fc=(0.8, 0.9, 0.9), ec="b", lw=2)
t = ax.text(0, 0, "Direction", ha="center", va="center", rotation=45,
size=15,
bbox=bbox_props)
bb = t.get_bbox_patch()
bb.set_boxstyle("larrow", pad=0.6) #pad文本框大小
Annotating with Text with Box—注释文本加文字框
Example2:
t = ax.text(?0, 0, "Direction", ha="center", va="center", rotation=45, size=15,??bbox=dict(boxstyle="rarrow,pad=0.3", fc="cyan", ec="b", lw=2))
实现缩放图:Zoom
ConnectionPatch:图与图之间的连接
学习中。。。
?参考网址:Basic Usage — Matplotlib 3.5.1 documentation
|