当前位置:网站首页>Visualization Road (IX) detailed explanation of arrow class
Visualization Road (IX) detailed explanation of arrow class
2022-04-23 07:37:00 【The big pig of the little pig family】
Arrow class
1.Arrow Class introduction
Arrow3.4.1 Official documents
Here are maplotlib Inheritance graph in Library :
It can be seen from the picture that ,Arrow Class inherits from Patch Class is the basic parent class , Is specifically responsible for the various attributes and implementation of the arrow . However, the degree of freedom of this class is not very high, and it is impossible to accurately set all the attributes you want to specify , At the same time, keep in mind that the instance of this class is not what we often think arrow Return value of method . He returned to FancyArrow example .
1.1Arrow Class definition
class Arrow(x,
y,
dx,
dy,
width=1.0,
**kwargs)
Parameter description :
Parameters 1:x: floating-point , Specifies the end of the arrow X coordinate
Parameters 2:y: floating-point , Specifies the end of the arrow Y coordinate
Parameters 3:dx: floating-point , Specifies the of the arrow X Direction coordinates
Parameters 4:dy: floating-point , Specifies the of the arrow Y Direction coordinates
Parameters 5:width: floating-point , Specifies the scale factor for the width of the arrow , Default head width 0.6, Tail width 0.2
Parameters 6:kwargs: receive Patch attribute ,Patch See the reference link for properties .
Parameters, :
- Arrow Class specifies the arrow from **(x, y) Start , This coordinate is also used as the central coordinate of the tail of the arrow , From this point on , Point to (x + dx, y + dy)** until .
- width Property specifies the scale , Remember that proportion , Instead of specifying absolute values , It can be understood that the width of the head of the last arrow is 0.6width, The tail width is 0.2width.
- This kind of instance can be through add_artist perhaps add_patch Method is added to the frame .
1.2 Example show
1.2.1width Parameter display
We now change width The value of the parameter to see what happens . The example program is as follows :
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # Settings support Chinese
plt.rcParams['axes.unicode_minus'] = False # Set up - Number
# Initialize frame and data
figure, [(ax1, ax2), (ax3, ax4)] = plt.subplots(2, 2)
widths = [0.1, 1, 8, 15]
# drawing
for ax, num, width in zip([ax1, ax2, ax3, ax4], range(4), widths):
arrow = (plt.Arrow(5, 5, 3, 3, width=width)) #Arrow Create examples
ax.add_patch(arrow) # Add instance
ax.set_title('width=' + str(width), fontsize=25)
ax.set_xlabel('X', fontsize=15)
ax.set_ylabel('Y', fontsize=15)
ax.autoscale(True)
figure.subplots_adjust(hspace=0.5)
plt.show()
The result is as follows :
As can be seen from the above figure width Parameters refer to Magnification , Not absolute values , Head 、 The ratio of tail width is constant . Besides, you can see 5, 5) This coordinate corresponds to the midpoint of the tail , and (8, 8) Is the coordinate of the tip of the arrow head .
1.2.2 obtain 、 Set attribute display
Like the others matplotlib Class instances are consistent , Use get_property(value)、set_property(value), The former is used to get the current property , The latter is used to set the current property .property Represents the name of the property to be set ,value Represents the value to be set . The example program is as follows :
print('old linewidth=', arrow.get_linewidth())
arrow.set_linewidth(15)
print('new linewidth=', arrow.get_linewidth())
The program runs as follows :
old linewidth= 1.0
new linewidth= 15.0
1.2.3 Visual display
Arrow Class has few parameters and is concise ,width The parameters have been introduced , Therefore, I will not repeat too much . Concrete Patch See the reference link for details of the class , This example only shows the passing Patch Visualization of class attribute keyword parameters . The example program is as follows :
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # Settings support Chinese
plt.rcParams['axes.unicode_minus'] = False # Set up - Number
X = 5 #X coordinate
Y = 5 #Y coordinate
dx = 3 #X Coordinate increment
dy = 3 #Y Coordinate increment
width = 1.5 # Width ratio
fig, ax = plt.subplots(3, 3)
# Draw an example standard arrow
arrow0 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width)
ax[0, 0].add_patch(arrow0)
ax[0, 0].set_title('normal', fontsize=25)
# Change surface color
arrow1 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, facecolor='#FF0000')
ax[0, 1].add_patch(arrow1)
ax[0, 1].set_title('facecolor=#FF0000', fontsize=25)
# Change the width of the edge line
arrow2 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, edgecolor='#000000', linewidth=5)
ax[0, 2].add_patch(arrow2)
ax[0, 2].set_title('linewidth=5', fontsize=25)
# Change edge line color
arrow3 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, edgecolor='#0000FF')
ax[1, 0].add_patch(arrow3)
ax[1, 0].set_title('edgecolor=#0000FF', fontsize=25)
# Change Linetype
arrow4 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, edgecolor='#000000', linewidth=5, linestyle='--')
ax[1, 1].add_patch(arrow4)
ax[1, 1].set_title('linestyle=--', fontsize=25)
# Change the fill mode
arrow5 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, fill=False)
ax[1, 2].add_patch(arrow5)
ax[1, 2].set_title('fill=False', fontsize=25)
# Change fill shadow
arrow6 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, hatch='||')
ax[2, 0].add_patch(arrow6)
ax[2, 0].set_title('hatch=||', fontsize=25)
# Change transparency
arrow7 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, facecolor='#00FF00', edgecolor='#000000', linewidth=5, alpha=0.1)
ax[2, 1].add_patch(arrow7)
ax[2, 1].set_title('alpha=0.1', fontsize=25)
# Change visibility
arrow8 = plt.Arrow(x=X, y=Y, dx=dx, dy=dy, width=width, visible=False)
ax[2, 2].add_patch(arrow8)
ax[2, 2].set_title('visible=False', fontsize=25)
for i in range(3):
for j in range(3):
ax[i, j].autoscale(True)
fig.subplots_adjust(hspace=0.4, wspace=0.4)
plt.show()
The result is as follows :
3. Reference resources
版权声明
本文为[The big pig of the little pig family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617063859.html
边栏推荐
猜你喜欢
可视化常见问题解决方案(九)背景颜色问题
How does the public and Private Integrated walkie talkie realize cooperative work under multi-mode communication?
Javscript gets the real suffix of the file
keytool: command not found
Us photo cloud editing helps BiliBili upgrade its experience
Discussion on the outline of short video technology
菜菜的并发编程笔记 |(五)线程安全问题以及Lock解决方案
保洁阿姨都能看懂的中国剩余定理和扩展中国剩余定理
H5 case development
Educational Codeforces Round 81 (Rated for Div. 2)
随机推荐
积性函数前缀和——杜教筛
Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
el-table 横向滚动条固定在可视窗口底部
Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
可视化常见问题解决方案(九)背景颜色问题
keytool: command not found
推导式与正则式
后台管理系统框架,总有你想要的
[牛客挑战赛47]C.条件 (bitset加速floyd)
莫比乌斯反演
What is a closure?
页面动态显示时间(升级版)
MVCC(多版本并发控制)
关于素数的不到100个秘密
Object.create()原理,Object.create()规范,手写Object.create(),Object.create()用法
USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference
(扩展)BSGS与高次同余方程
el-select 中v-model绑定值,数据回显只显示value,不显示label
开发板如何ping通百度
可视化之路(十一)matplotlib颜色详解