plt.annotate()函数解析(最清晰的解释)

plt.annotate()函数解析(最清晰的解释)plt annotate 函数用于标注文字 plt annotate s str xy x y xytext l1 l2 参数 s 为注释文本内容 xy 为被注释的坐标点 xytext 为注释文字的坐标位置 xycoords 参数如下 figurepoints 图左下角的点 figurepixels 图左下角的像素 figur

欢迎关注WX公众号:【程序员管小亮】

plt.annotate()函数用于标注文字。
plt.annotate(s='str', xy=(x,y) , xytext=(l1,l2) , ... ) 

参数:

  • s 为注释文本内容
  • xy 为被注释的坐标点
  • xytext 为注释文字的坐标位置
  • xycoords 参数如下:
    • figure points:图左下角的点
    • figure pixels:图左下角的像素
    • figure fraction:图的左下部分
    • axes points:坐标轴左下角的点
    • axes pixels:坐标轴左下角的像素
    • axes fraction:左下轴的分数
    • data:使用被注释对象的坐标系统(默认)
    • polar(theta,r):if not native ‘data’ coordinates t
  • weight 设置字体线型
    • {‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’}
  • color 设置字体颜色
    • {‘b’, ‘g’, ‘r’, ‘c’, ‘m’, ‘y’, ‘k’, ‘w’}
    • ‘black’,’red’等
    • [0,1]之间的浮点型数据
    • RGB或者RGBA, 如: (0.1, 0.2, 0.5)、(0.1, 0.2, 0.5, 0.3)等
  • arrowprops #箭头参数,参数类型为字典dict
    • width:箭头的宽度(以点为单位)
    • headwidth:箭头底部以点为单位的宽度
    • headlength:箭头的长度(以点为单位)
    • shrink:总长度的一部分,从两端“收缩”
    • facecolor:箭头颜色
  • bbox给标题增加外框 ,常用参数如下:
    • boxstyle:方框外形
    • facecolor:(简写fc)背景颜色
    • edgecolor:(简写ec)边框线条颜色
    • edgewidth:边框线条大小
例子1:
import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 6) y = x * x plt.plot(x, y, marker='o') for xy in zip(x, y): plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points') plt.show() 

在这里插入图片描述

例子2:

把weight参数改成heavy。

import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 6) y = x * x plt.plot(x, y, marker='o') for xy in zip(x, y): plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points', weight='heavy') plt.show() 

在这里插入图片描述

例子3:

把color参数改成y。

import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 6) y = x * x plt.plot(x, y, marker='o') for xy in zip(x, y): plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points', color='y') plt.show() 

在这里插入图片描述

例子4:

把arrowprops参数改成通过dict传入参数(facecolor = “r”, headlength = 10, headwidth = 30, width = 20)。

import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 6) y = x * x plt.plot(x, y, marker='o') for xy in zip(x, y): plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points', arrowprops = dict(facecolor = "r", headlength = 10, headwidth = 30, width = 20)) plt.show() 

在这里插入图片描述

例子5:

把bbox参数改成通过dict传入参数(boxstyle=‘round,pad=0.5’, fc=‘yellow’, ec=‘k’,lw=1 ,alpha=0.5)。

import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 6) y = x * x plt.plot(x, y, marker='o') for xy in zip(x, y): plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points', bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='k', lw=1, alpha=0.5) plt.show() 

在这里插入图片描述

例子6:

把arrowprops参数改成通过dict传入参数(facecolor=‘black’, shrink=0.05)。

import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 6) y = x * x plt.plot(x, y, marker='o') for xy in zip(x, y): plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05)) plt.show() 

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/224746.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午11:14
下一篇 2026年3月17日 上午11:15


相关推荐

  • python csv文件数据写入和读取(适用于超大数据量)

    python csv文件数据写入和读取(适用于超大数据量)文章目录pythoncsv文件数据写入和读取(适用于超大数据量)pythoncsv文件数据写入和读取(适用于超大数据量)一般情况下由于我们使用的数据量比较小,因此可以将数据一次性整体读入或者写入,而且可以一次性对数据进行加工和处理。但是当数据量比较大,比如有5G的数据量,这个时候想要一次性对所有数据进行操作就比较困难了。所以需要逐条将数据进行处理。importcsv#在最开始创…

    2022年7月20日
    56
  • linux 误删文件恢复_centos删除的文件能恢复吗

    linux 误删文件恢复_centos删除的文件能恢复吗本文参考http://write.blog.csdn.net/postedit?ticket=ST-491405-OGjDDusZeyMgVQ7bHW7f-passport.csdn.net前言作为一个多用户、多任务的操作系统,Linux下的文件一旦被删除,是难以恢复的。尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是其他用户和一些有写盘动作的进程会很快覆盖这些数据。不过……

    2022年8月21日
    9
  • setfacl命令基本用法[通俗易懂]

    setfacl命令基本用法[通俗易懂]setfacl命令可以用来细分linux下的文件权限。chmod命令可以把文件权限分为u,g,o三个组,而setfacl可以对每一个文件或目录设置更精确的文件权限。换句话说,setfacl可以更精确的控制权限的分配。比如:让某一个用户对某一个文件具有某种权限。这种独立于传统的u,g,o的rwx权限之外的具体权限设置叫ACL(AccessControlList)ACL可以针

    2022年6月16日
    49
  • java 幂等性

    java 幂等性理解 HTTP 幂等性基于 HTTP 协议的 WebAPI 是时下最为流行的一种分布式服务提供方式 无论是在大型互联网应用还是企业级架构中 我们都见到了越来越多的 SOA 或 RESTful 的 WebAPI 为什么 WebAPI 如此流行呢 我认为很大程度上应归功于简单有效的 HTTP 协议 HTTP 协议是一种分布式的面向资源的网络应用层协议 无论是服务器端提供 Web 服务 还是客户端消费 Web 服务都非常

    2026年3月16日
    3
  • C中的LINQ

    C中的LINQ一 什么是 LINQ 二 用法 where 查询特定条件 usingSystem usingSystem Collections Generic usingSystem Linq classMainCla staticList Person personList newList Person newPerson Id 1 Name 小明 Age 20 Score 100 Person Person

    2026年3月18日
    1
  • 明明白白你的Linux服务器——网络篇

    明明白白你的Linux服务器——网络篇前言 希望大家看完此文后 能很清楚明白你的服务器的网络情况 能很轻松的配置其网络环境 毕竟 Linux 服务器在装完系统 配置其网络环境是每一个 systemadmini 的职能 一 服务器的网络配置在服务器的网络配置时 喜欢图形的朋友可用 setup 或 system config network 来配置 网卡配置文件为 etc sysconfig

    2026年3月17日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号