将yticklabels设置为字符串

时间:2015-10-27 23:22:31

标签: python matplotlib

我的数据集中的单元格数组如下所示。

a = [datetime.datetime(2015, 10, 15, 14, 57, 23, 793), datetime.datetime(2015, 10, 15, 15, 42, 58, 448), datetime.datetime(2015, 10, 15, 15, 44, 46, 892), datetime.datetime(2015, 10, 15, 15, 45, 10, 770), datetime.datetime(2015, 10, 15, 15, 45, 23, 33), datetime.datetime(2015, 10, 15, 15, 45, 53, 582), datetime.datetime(2015, 10, 15, 15, 46, 17, 582), datetime.datetime(2015, 10, 15, 15, 46, 21, 676), datetime.datetime(2015, 10, 15, 15, 47, 1, 246), datetime.datetime(2015, 10, 15, 15, 47, 27, 558)]
b = [5, 4, 5, 4, 6, 5, 4, 5, 4, 6]

plt.plot(a,b,'ro-')

这个情节很好但我想在看到特定数字时在地图上显示字符串。

e.g。 4 - > apple 5 - >芒果和6 - >橙

是否可以使用matplotlib.pyplot

2 个答案:

答案 0 :(得分:0)

看起来像for (int i=0; i < 6; i++) { if (i < 3) { System.out.println("*****====="); } else { System.out.println("=========="); } } 就是你想要的:

Matplotlib: How to put individual tags for a scatter plot

Label python data points on plot

matplotlib scatter plot with different text at each data point

答案 1 :(得分:0)

您可以通过设置yticklabels

来完成
plt.gca().set_yticks([4,5,6]) 
plt.gca().set_yticklabels(["apple", "mango", "orange"])