matplotlib添加 annotation 箭头标注

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi, np.pi, 1000)
cosy = np.cos(x)
siny = np.sin(x)

xo = np.pi * 3/4
yo_cos = np.cos(xo)
yo_sin = np.sin(xo)

plt.xlim(min(x), max(x))
plt.ylim(min(cosy), max(cosy)+0.5)
plt.plot(x, cosy, label='cos')
plt.plot(x, siny, label='sin')

# 画散点
plt.scatter(xo, yo_sin, edgecolors="skyblue", facecolor='skyblue',s=90, zorder=3)
plt.scatter(xo, yo_cos, edgecolors="green", s=10)
# 设置坐标刻度
plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi *3/4, np.pi],)

# 设置坐标轴
ax = plt.gca()
ax.spines['left'].set_position(('data', 0))
ax.spines['bottom'].set_position(('data', 0))
ax.spines['right'].set_position(('data', 0))
ax.spines['top'].set_position(('data', 0))

# 设置annotation
plt.annotate('key point1',
             xy=(xo, yo_cos),
             )
"""
plt.annotate('文本', xy=目标位置, xycoords=目标位置的坐标系, xytext=文本的位置,textcoords='offset points',fontsize, arrowprops=箭头属性)
"""
plt.annotate('key point2',
             xy=(xo, yo_sin),
             xytext=(15, 15),
             textcoords='offset points',
             arrowprops=dict(arrowstyle='->')
             )
#设置图例
plt.show()

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值