本系列文章配套代码获取有以下两种途径:
-
通过百度网盘获取:
链接:https://pan.baidu.com/s/1jG-rGG4QMuZu0t0kEEl7SA?pwd=mnsj
提取码:mnsj
-
前往GitHub获取:
https://github.com/returu/Data_Visualization
箭头样式:
关键词参数 |
说明 |
width | 箭头的宽度,单位是点 |
headwidth | 箭头头部的宽度,单位是点 |
headlength | 箭头头部的长度,单位是点 |
shrink | 箭头两端收缩的百分比 |
? | 任意matplotlib.patches.FancyArrowPatch属性 |
类别 |
箭头样式 |
属性 |
Curve | – | None |
CurveA | <- | head_length=0.4, head_width=0.2 |
CurveB | -> | head_length=0.4, head_width=0.2 |
CurveAB | <-> | head_length=0.4, head_width=0.2 |
CurvefilledA |
<|- | head_length=0.4, head_width=0.2 |
CurvefilledB | -|> | head_length=0.4, head_width=0.2 |
CurvefilledAB | <|-|> | head_length=0.4, head_width=0.2 |
BrackedA | ]- | widthA=1.0, lengthA=0.2, angleA=0 |
BrackedB | -] | widthB=1.0, lengthB=0.2, angleB=0 |
BrackedAB | ]-[ |
widthA=1.0, lengthA=0.2, angleA=0 widthB=1.0, lengthB=0.2, angleB=0 |
BarAB | |-| |
widthA=1.0, lengthA=0.2, widthB=0, angleB=0 |
BrackedCurve | ]-> | widthA=1.0, lengthA=0.2, angleA=None |
CurveBarcked | <-[ | widthB=1.0, lengthB=0.2, angleB=None |
Simple | simple | head_length=0.5, head_width=0.5, tail_width=0.2 |
Fancy | fancy | head_length=0.4, head_width=0.4, tail_width=0.4 |
Wedge | wedge |
tail_width=0.3, shrink_factor=0.5 |
ArrowStyle_list = ['-', '<-', '->', '<->', '<|-','-|>', '<|-|>', ']-', '-[', ']-[', '|-|', ']->', '<-[', 'simple', 'fancy', 'wedge']
ArrowStyle_name_list = ['Curve', 'CurveA', 'CurveB', 'CurveAB', 'CurvefilledA','CurvefilledB', 'CurvefilledAB', 'BrackedA', 'BrackedB', 'BrackedAB', 'BarAB', 'BrackedCurve', 'CurveBarcked', 'simple', 'fancy', 'wedge']
fig, axes = plt.subplots(4, 4 , figsize=(10, 10))
for i in range(len(ArrowStyle_list)):
axes[i//4,i%4].annotate(text=ArrowStyle_name_list[i], # 注释文字
fontweight='bold', # 字体粗细
color='m', # 字体颜色
xy=(0.2,0.2),
xytext=(0.4,0.8),
arrowprops=dict(
facecolor='r', # 箭头填充色
edgecolor='k', # 箭头边框色
arrowstyle=ArrowStyle_list[i]) # 箭头样式
)
axes[i//4,i%4].set_xticks([])
axes[i//4,i%4].set_yticks([])
连接样式:
另外,FancyArrowPatch中的connectionstyle(连接样式)包含样式参看下表(angle3和arc3中的3意味着所得到的路径是二次样条段,即三个控制点):
关键词 |
属性说明 |
angle |
angleA=90, angleB=0, rad=0.0 |
angle3 |
angleA=90, angleB=0 |
arc | angleA=90, angleB=0, armA=None, armB=None, rad=0.0 |
arc3 | rad=0.0 |
bar | armA=0.0, armB=0.0, fraction=0.3, angle=None |
通过设置参数connectionstyle的具体值,绘制出以下连接样式:
connectionstyle_list = ["angle,angleA=-90,angleB=180,rad=0",
"angle,angleA=-90,angleB=180,rad=5",
"angle,angleA=-90,angleB=10,rad=5",
"angle3,angleA=90,angleB=0",
"angle3,angleA=0,angleB=90",
"arc,angleA=-90,angleB=0,armA=30,armB=30,rad=0",
"arc,angleA=-90,angleB=0,armA=30,armB=30,rad=5",
"arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0",
"arc3,rad=0.",
"arc3,rad=0.3",
"arc3,rad=-0.3",
"bar,fraction=0.3",
"bar,fraction=0.5,angle=60",
"bar,fraction=0.3,armA=30,armB=30",
"bar,fraction=-0.3",
"bar,angle=180,fraction=-0.2"]
connectionstyle_name = ["anglenangleA=-90nangleB=180nrad=0",
"anglenangleA=-90nangleB=180nrad=5",
"anglenangleA=-90nangleB=10nrad=5",
"angle3nangleA=90nangleB=0",
"angle3nangleA=0nangleB=90",
"arcnangleA=-90nangleB=0narmA=30narmB=30nrad=0",
"arcnangleA=-90nangleB=0narmA=30narmB=30nrad=5",
"arcnangleA=-90nangleB=0narmA=0narmB=40nrad=0",
"arc3nrad=0.",
"arc3nrad=0.3",
"arc3nrad=-0.3",
"barnfraction=0.3",
"barnfraction=0.5nangle=60",
"barnfraction=0.3narmA=30narmB=30",
"barnfraction=-0.3",
"barnangle=180nfraction=-0.2"]
fig, axes = plt.subplots(4, 4 , figsize=(20, 20))
for i in range(len(connectionstyle_list)):
axes[i//4,i%4].annotate(text=connectionstyle_name[i], # 注释文字
fontweight='bold', # 字体粗细
fontsize=14, # 字体大小
color='m', # 字体颜色
xy=(0.2,0.2),
xytext=(0.5,0.6),
arrowprops=dict(
facecolor='r', # 箭头填充色
edgecolor='k', # 箭头边框色
arrowstyle='->', # 箭头样式
connectionstyle=connectionstyle_list[i] # 连接样式
)
)
axes[i//4,i%4].set_xticks([])
axes[i//4,i%4].set_yticks([])
更多内容可以前往官网查看:
https://matplotlib.org/stable/
本篇文章来源于微信公众号: 码农设计师