plt.text()函数解析

plt.text(x, y, s, fontsize, verticalalignment,horizontalalignment,rotation , transform, *kwargs)

参数:

  • x,y:表示坐标值上的值
  • s:表示说明文字
  • fontsize:表示字体大小
  • verticalalignment:垂直对齐方式 ,参数:[ ‘center’ | ‘top’ | ‘bottom’ | ‘baseline’ ]
  • horizontalalignment:水平对齐方式 ,参数:[ ‘center’ | ‘right’ | ‘left’ ]
  • xycoords选择指定的坐标轴系统:
    • figure points:图左下角的点
    • figure pixels:图左下角的像素
    • figure fraction:图的左下部分
    • axes points:坐标轴左下角的点
    • axes pixels:坐标轴左下角的像素
    • axes fraction:左下轴的分数
    • data:使用被注释对象的坐标系统(默认)
    • polar(theta,r):if not native ‘data’ coordinates t
  • bbox给标题增加外框 ,如 bbox=dict(facecolor=‘red’, alpha=0.5) 等。常用参数如下:
    • boxstyle:方框外形
    • facecolor:(简写fc)背景颜色
    • edgecolor:(简写ec)边框线条颜色
    • edgewidth:边框线条大小
    • pad:背景往外扩展填充大小
    • alpha:背景颜色透明度
  • rotation:标签的旋转角度,以逆时针计算,取整
  • family :设置字体
  • style: 设置字体的风格。{'normal', 'italic', 'oblique'}:{'正常', '斜体', '斜'}。
  • weight:设置字体的粗细。'normal':正常, 'regular':常规, 'roman':罗马, 'black':黑体, 'bold':粗体。
  • color:注释文本内容的字体颜色。例:{‘b’, ‘g’, ‘r’, ‘c’, ‘m’, ‘y’, ‘k’, ‘w’}。RGB或者RGBA, 如: (0.1, 0.2, 0.5)、(0.1, 0.2, 0.5, 0.3)等
  • 更改xy定位的坐标系。
    • 直接指定坐标值:例如,x=0.5, y=0.5表示文本注释位于坐标轴范围内的位置(0.5, 0.5)处;
    • 使用坐标轴比例:例如,x=0.5, y=0.9, transform=ax.transAxes表示文本注释位于坐标轴的上方,横向中心为0.5,纵向距离顶部0.1倍的高度处;
    • 使用数据坐标系:例如,x=2, y=1, transform=ax.transData表示文本注释位于数据坐标系中的点(2, 1)处。

例子:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi)
y1 = np.sin(x)

fig, axs = plt.subplots(figsize=(4, 3))
axs.plot(x, y1)
plt.text(x=0.0, y=0.9,
         s="a)",
         weight="regular",
         bbox=dict(facecolor="w", alpha=1,edgecolor="w",boxstyle='square',pad=0.5))
plt.show()

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

清纯世纪

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

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

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

打赏作者

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

抵扣说明:

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

余额充值