如何显示我在y轴上绘制的每个点的值的标签?
我目前正在密谋:
d=[2,5,10,20,30,40,50,70,100,200]
t0=[0.04,0.08,0.15,0.4,0.6,0.8,1.0,1.4,2.1,5.5]
fig, ax = plt.subplots()
plt.plot(d,t0,marker='o')
xmajorLocator = MultipleLocator(10)
xmajorFormatter = FormatStrFormatter('%d')
xminorLocator = MultipleLocator(1)
ymajorLocator = MultipleLocator(0.5)
ymajorFormatter = FormatStrFormatter('%.2f')
yminorLocator = MultipleLocator(0.05)
ax.xaxis.set_major_locator(xmajorLocator)
ax.xaxis.set_major_formatter(xmajorFormatter)
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_major_locator(ymajorLocator)
ax.yaxis.set_major_formatter(ymajorFormatter)
ax.yaxis.set_minor_locator(yminorLocator)
xlim([0,250])
show()
我只想标记t0列表的值并显示在y轴上,同时保持当前标记和刻度格式。
答案 0 :(得分:3)
import matplotlib.pyplot as plt
d=[2,5,10,20,30,40,50,70,100,200]
t0=[0.04,0.08,0.15,0.4,0.6,0.8,1.0,1.4,2.1,5.5]
fig, ax = plt.subplots()
plt.plot(d,t0,marker='o')
ax.set_xticks(d)
ax.set_yticks(t0)
plt.show()