Justheartyoung 发表于 2020-5-26 10:42:41

请大佬帮忙看看 谢谢

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-3,3,50)
y1 = 2*x + 1

plt.figure()
plt.plot(x, y1)

plt.xlim((-1,2))
plt.ylim((-2,3))
plt.xlabel('I am x')
plt.ylabel('I am y')

new_ticks = np.linspace(-1,2,5)
print(new_ticks)
plt.xticks(new_ticks)
plt.yticks([-2,-1.8,-1,1.22,3],['$relly bad$',r'$bad\alpha$',r'$normal$',r'$good$',r'$rellygood$'])

x0 = 0.5
y0 = 2 * x0 + 1
plt.scatter(x0,y0,s=50,color='b')
plt.plot(,,'k--',lw=2.5)

#method 1
plt.annotate(r'$2x+1=%s$' %y0,xy=(x0,y0),xycoords='data',xytext=(+30,-30),textcoords='offset point',
             fontsize=16,arrowprops=dict(arrowstyle='->',connectionstyle='arc3,rad=.2'))

plt.show()

运行以后出现以下错误提示:
ValueError: offset point is not a recognized coordinate
问题是出在这一句吗:xytext=(+30,-30),textcoords='offset point',?

Twilight6 发表于 2020-5-26 11:05:17

错在这个:textcoords='offset point'
你粗心大意少了个s:textcoords='offset points'
页: [1]
查看完整版本: 请大佬帮忙看看 谢谢