我试图在matplotlib中使用一组日期值和计数构建一个线图,但是用第二组值对同一个图进行注释。到目前为止,我有:
import matplotlib.pyplot as plt
count_dates_dict = {u'Mon Feb 13 05:19:09 +0000 2012': 18, u'Mon Feb 13 05:19:04 +0000 2012': 36, u'Mon Feb 13 05:19:03 +0000 2012': 32, u'Mon Feb 13 05:18:58 +0000 2012': 14, u'Mon Feb 13 05:19:10 +0000 2012': 33, u'Mon Feb 13 05:19:02 +0000 2012': 28, u'Mon Feb 13 05:18:59 +0000 2012': 33, u'Mon Feb 13 05:19:11 +0000 2012': 38, u'Mon Feb 13 05:19:12 +0000 2012': 41, u'Mon Feb 13 05:19:08 +0000 2012': 31, u'Mon Feb 13 05:19:07 +0000 2012': 41, u'Mon Feb 13 05:19:06 +0000 2012': 46, u'Mon Feb 13 05:19:05 +0000 2012': 33, u'Mon Feb 13 05:19:00 +0000 2012': 35, u'Mon Feb 13 05:19:01 +0000 2012': 28, u'Mon Feb 13 05:19:13 +0000 2012': 13}
sorted_annotation_dates_dict = {u'Mon Feb 13 05:19:09 +0000 2012': 1, u'Mon Feb 13 05:19:03 +0000 2012': 1, u'Mon Feb 13 05:19:02 +0000 2012': 1, u'Mon Feb 13 05:18:59 +0000 2012': 1, u'Mon Feb 13 05:19:11 +0000 2012': 1, u'Mon Feb 13 05:19:12 +0000 2012': 1, u'Mon Feb 13 05:19:07 +0000 2012': 1, u'Mon Feb 13 05:19:00 +0000 2012': 1, u'Mon Feb 13 05:19:01 +0000 2012': 1, u'Mon Feb 13 05:19:13 +0000 2012': 1}
fig = plt.figure(figsize=(15,5))
ax = plt.axes()
ax2 = plt.axes()
plt.xticks(range(0, len(count_dates_dict.values())), sorted(count_dates_dict.keys(), reverse=False), rotation=90, color = 'b')
ax.plot(count_dates_dict.values(), color = 'g')
for item in sorted(sorted_annotation_dates_dict).keys():
ax.annotate(item, xytext=('Point of Intrest'), rotation=90, arrowprops=dict(connectionstyle="arc3"), xy=(item))
plt.show()
显然,这也会引发一个错误,即需要为注释解包的值太多。我不确定我是否完全理解注释想要什么。我假设xy=是箭头的一组点?任何帮助都会受到感激。你知道吗
我不清楚,您希望注释发生在哪里(特别是y坐标),但我希望这就是您要寻找的。无论如何,这个例子可以帮助你实现最终目标。你知道吗
这会导致
相关问题 更多 >
编程相关推荐