python中matplotlib的使用(二)

1、设置刻度、图例和坐标标签字体大小

1)、设置刻度大小

在这里插入图片描述

plt.xticks(fontsize=20)
plt.yticks(fontsize=20)

在这里插入图片描述

2)、设置坐标大小

plt.xlabel(..., fontsize=20)
plt.ylabel(..., fontsize=20)

在这里插入图片描述

3)、设置图例字体大小

plt.legend(..., fontsize=20)

2、添加注释(annotate)

plt.annotate('注释', xy=(2, 1), xytext=(3, 4),color='r',size=15,arrowprops=dict(facecolor='g', shrink=0.05))

在这里插入图片描述
PS:

  • 参数xy是需要加入注释的位置。
  • 参数xytext是注释内容的位置。
  • 参数xycoords 如下:
参数介绍
figure pointspoints from the lower left of the figure 点在图左下方
figure pixelspixels from the lower left of the figure 图左下角的像素
figure fractionfraction of figure from lower left 左下角数字部分
axes pointspoints from lower left corner of axes 从左下角点的坐标
axes pixelspixels from lower left corner of axes 从左下角的像素坐标
axes fractionfraction of axes from lower left 左下角部分
datause the coordinate system of the object being annotated(default) 使用的坐标系统被注释的对象(默认)
polar(theta,r)if not native ‘data’ coordinates t
  • 参数color设置字体颜色。
  • 参数extcoords 设置注释文字偏移量:
参数坐标系
‘figure points’距离图形左下角的点数量
‘figure pixels’距离图形左下角的像素数量
‘figure fraction’0,0 是图形左下角,1,1 是右上角
‘axes points’距离轴域左下角的点数量
‘axes pixels’距离轴域左下角的像素数量
‘axes fraction’0,0 是轴域左下角,1,1 是右上角
‘data’使用轴域数据坐标系
  • 参数size设置注释字体大小。
  • 参数verticalalignment:垂直对齐方式 ,参数:[ ‘center’ | ‘top’ | ‘bottom’ | ‘baseline’ ]
  • 参数horizontalalignment:水平对齐方式 ,参数:[ ‘center’ | ‘right’ | ‘left’ ]
  • 参数arrowprops中有关参数是箭头的相关信息,类型为dict:
    使用方式:
 arrowprops=dict(facecolor='g', shrink=0.05)
参数介绍
widththe width of the arrow in points 点箭头的宽度
headwidththe width of the base of the arrow head in points 在点的箭头底座的宽度
headlengththe length of the arrow head in points 点箭头的长度
shrinkfraction of total length to ‘shrink’ from both ends 总长度为分数“缩水”从两端
facecolor箭头颜色
  • 参数bbox是有关注释边框的有关参数dict类:
    使用方式:
  bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='k',lw=1 ,alpha=0.5) 
参数介绍
boxstyle方框外形
facecolor(简写fc)背景颜色
edgecolor(简写ec)边框线条颜色
edgewidth边框线条大小

**PS:**常用的方框外形有:

  1. square
  2. sawtooth
  3. roundtooth
  4. raarow
  5. larrow
  6. round
  7. round4

3、文本

plt.text(6, 5, "test", size=50, rotation=30.,ha="center", va="center",bbox=dict(boxstyle="round",ec=(1., 0.5, 0.5),fc=(1., 0.8, 0.8),))

在这里插入图片描述

  • 参数x,y:表示坐标值上的值 。
  • 参数color设置字体颜色。
  • 参数fontsize设置字体大小 。
  • 参数verticalalignment:垂直对齐方式 ,参数:[ ‘center’| ‘top’ | ‘bottom’ | ‘baseline’ ]
  • 参数horizontalalignment:水平对齐方式 ,参数:[‘center’ | ‘right’ | ‘left’ ]
  • 参数xycoords选择指定的坐标轴系统,参数相关内容同上。
  • 参数bbox给标题增加外框 ,参数相关内容同上。

代码参考:

https://github.com/ZhangJiangtao-0108/pythonmatplotlib_example.py文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值