Matplotlib:在图表上每个点旁边显示值

Matplotlib:在图表上每个点旁边显示值,matplotlib,Matplotlib,是否可以在图表上显示每个点旁边的值: 点上显示的值为:[7、57、121、192、123、240、546] values = list(map(lambda x: x[0], result)) #[7, 57, 121, 192, 123, 240, 546] labels = list(map(lambda x: x[1], result)) #['1950s', '1960s', '1970s', '1980s', '1990s', '2000s', '2010s'] plt.plot(

是否可以在图表上显示每个点旁边的值:

点上显示的值为:[7、57、121、192、123、240、546]

values = list(map(lambda x: x[0], result)) #[7, 57, 121, 192, 123, 240, 546]
labels = list(map(lambda x: x[1], result)) #['1950s', '1960s', '1970s', '1980s', '1990s', '2000s', '2010s']

plt.plot(labels, values, 'bo')
plt.show()
这是我当前的图表代码


我想知道图表上显示的每个点的值,目前我只能根据y轴预测值。

根据您的值,这里有一个使用
plt.text的解决方案

fig = plt.figure()
ax = fig.add_subplot(111)
values = [7, 57, 121, 192, 123, 240, 546]
labels = ['1950s', '1960s', '1970s', '1980s', '1990s', '2000s', '2010s']

plt.plot(range(len(labels)), values, 'bo') # Plotting data
plt.xticks(range(len(labels)), labels) # Redefining x-axis labels

for i, v in enumerate(values):
    ax.text(i, v+25, "%d" %v, ha="center")
plt.ylim(-10, 595)
输出


基于
plt.注释的解决方案

fig=plt.figure()
ax=图添加_子批次(111)
值=[7,57,121,192,123,240,546]
标签=['1950年代'、'1960年代'、'1970年代'、'1980年代'、'1990年代'、'2000年代'、'2010年代']
plt.绘图(范围(透镜(标签)),值,'bo')#绘图数据
plt.xticks(范围(透镜(标签)),标签)#重新定义x轴标签
对于枚举中的i,v(值):
ax.annotate(str(v),xy=(i,v),xytext=(-7,7),textcoords='offset points')
plt.ylim(-10595)
输出:


在代码中添加更多细节,以便可以复制您的体形。目前,如果不知道具体情况,这一点都不好variables@Bazingaa我编辑了这个问题。令人惊讶的回答。非常感谢。