plt.text()用法

本文详细介绍了matplotlib库的plt.text()函数,用于在图表上添加文本。内容涵盖了位置设定、字体样式调整、水平和垂直对齐方式、旋转角度以及透明度和背景颜色等关键参数的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs)
  • x,y:位置(position)

  • s:该position需要展示的值

  • fontdict:字体

  • withdash:宽度

以下为其他常用参数1:

fontsize设置字体大小

fontweight设置字体粗细,可选参数 [‘light’, ‘normal’, ‘medium’, ‘semibold’, ‘bold’, ‘heavy’, ‘black’]

fontstyle设置字体类型,可选参数[ ‘normal’ | ‘italic’ | ‘oblique’ ],italic斜体,oblique倾斜

verticalalignment设置水平对齐方式 ,可选参数 : ‘center’ , ‘top’ , ‘bottom’ ,‘baseline’

horizontalalignment设置垂直对齐方式,可选参数:left,right,center

rotation(旋转角度)

alpha透明度,参数值0至1之间

backgroundcolor标题背景颜色

bbox给标题增加外框 ,常用参数如下:

boxstyle方框外形
facecolor(简写fc)背景颜色
edgecolor(简写ec)边框线条颜色
edgewidth边框线条大小

如 bbox=dict(facecolor='red', alpha=0.5)
plt.text(a,b,"%.3f"% b,ha="center",va= "bottom") #格式化字符串,保留3位小数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

炫云云

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值