本文详细介绍如何给一张图添加注释文字、指引箭头。
本文速览
不同axes之间注释箭头连接文本
image
之前介绍的venn图中个性化添加注释文本框
image
目录
1、添加文本(matplotlib.pyplot.text)
文本基本参数设置
给文本加上背景框
背景文本框形状
2、添加注释(matplotlib.pyplot.annotate)
基本参数设置
修改箭头形状
箭头弯曲
跨子图注释
1、添加文本(matplotlib.pyplot.text)
语法:matplotlib.pyplot.text(x, y, s, fontdict=None, **kwargs)
文本基本参数设置
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
plt.figure(figsize=(5,4),dpi=120)
plt.plot([1,2,5],[7,8,9])
plt.text(x=2.2,#文本x轴坐标
y=8, #文本y轴坐标
s='basic unility of text', #文本内容
rotation=1,#文字旋转
ha='left',#x=2.2是文字的左端位置,可选'center', 'right', 'left'
va='baseline',#y=8是文字的低端位置,可选'center', 'top', 'bottom', 'baseline', 'center_baseline'
fontdict=dict(fontsize=12, color='r',
family='monospace',#字体,可选'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'
weight='bold',#磅值,可选'light', 'normal', 'medium', 'semibold', 'bold', &