python中的annotate函数如何使用

发布时间:2022-05-16 09:17:02 作者:iii
来源:亿速云 阅读:233

今天小编给大家分享一下python中的annotate函数如何使用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

python的annotate函数

annotate函数

该函数的详细参数可调用内置属性__doc__查看。

	import matplotlib.pyplot as plt
    # plt.annotate(str, xy=data_point_position, xytext=annotate_position, 
    #              va="center",  ha="center", xycoords="axes fraction", 
    #              textcoords="axes fraction", bbox=annotate_box_type, arrowprops=arrow_style)
    # str是给数据点添加注释的内容,支持输入一个字符串
    # xy=是要添加注释的数据点的位置
    # xytext=是注释内容的位置
    # bbox=是注释框的风格和颜色深度,fc越小,注释框的颜色越深,支持输入一个字典
    # va="center",  ha="center"表示注释的坐标以注释框的正中心为准,而不是注释框的左下角(v代表垂直方向,h代表水平方向)
    # xycoords和textcoords可以指定数据点的坐标系和注释内容的坐标系,通常只需指定xycoords即可,textcoords默认和xycoords相同
    # arrowprops可以指定箭头的风格支持,输入一个字典
    # plt.annotate()的详细参数可用__doc__查看,如:print(plt.annotate.__doc__)

例1:

	import matplotlib.pyplot as plt
    fig = plt.figure(1, facecolor='white')
    fig.clf()
    plt.annotate('a decision node', (0.1, 0.5), (0.5, 0.1), va="center",  ha="center",
                 xycoords="axes fraction", textcoords="axes fraction", 
                 bbox=dict(box, fc="0.8"), arrowprops=dict(arrow))
    plt.show()

结果如下:

python中的annotate函数如何使用

例2:给注释和数据点指定不同的坐标系

	import matplotlib.pyplot as plt
    fig = plt.figure(1, facecolor='white')
    fig.clf()
    # 这里指定数据点的坐标系原点在xy轴的左下角,而注释的坐标系原点在这个图像(figure)的左下角
    # 所以才会出现注释内容下移覆盖了x轴
    plt.annotate('a decision node', (0.1, 0.5), (0.5, 0.1), va="center",  ha="center",
                 xycoords="axes fraction", textcoords="figure fraction", 
                 bbox=dict(box, fc="0.8"), arrowprops=dict(arrow))
    plt.show()

结果如下:

python中的annotate函数如何使用

可视化annotate()函数解析

函数功能:添加图形内容细节的指向型注释文本。

调用签名:

plt.annotate(string, xy=(np.pi/2, 1.0), xytext=((np.pi/2)+0.15, 1,5), weight="bold", color="b", arrowprops=dict(arrow, connection, color="b"))

代码实现:

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.05, 10, 1000)
y = np.sin(x)
plt.plot(x, y, ls="-.", lw=2, c="c", label="plot figure")
plt.legend()
plt.annotate("maximum", xy=(np.pi/2, 1.0), xytext=((np.pi/2)+1.0, .8),
             weight="bold", color="b", 
             arrowprops=dict(arrow, connection, color="b"))
plt.show()

python中的annotate函数如何使用

以上就是“python中的annotate函数如何使用”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

推荐阅读:
  1. 如何使用python中的del函数
  2. 如何使用django ORM中values和annotate

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python annotate

上一篇:C#如何使用WebClient实现上传下载

下一篇:Python人工智能实战之以图搜图怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》