2021-01-19

1 Annoate

关于annotate更多的参数解释可以查看官方文档的注释内容,写的很全面,这里给出几个常用的参数用法,能够更好的掌握annotate的用法。

主要的参数:

text : str

The text of the annotation. s is a deprecated synonym for this parameter.

xy : (float, float)

The point (x,y) to annotate.

xytext : (float, float), optional

The position (x,y) to place the text at. If None, defaults to xy.

import numpy as np
import matplotlib.pyplot as plt

font = {'family': 'serif',
        'color': 'darkred',
        'weight': 'normal',
        'size': 16,
       }

x = np.linspace(0.0, 5.0, 10000)
y = np.cos(2 * np.pi * x) * np.exp(-x)

plt.plot(x, y, 'k')
plt.title('Damped exponential decay', fontdict=font)
plt.text(2, 0.65, r'$\cos(2 \pi t) \exp(-t)$', fontdict=font)
plt.xlabel('time (s)', fontdict=font)
plt.ylabel('voltage (mV)', fontdict=font)

# Tweak spacing to prevent clipping of ylabel
plt.subplots_adjust(left=0.15)
plt.annotate(s="matplotlib annotate", xy=(0.46, -0.617), xytext=(0.8, -0.5), arrowprops={"arrowstyle": "->"}, fontsize=16)
plt.show()

最终结果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值