我尝试找到解决方案以解决此错误,但我无法得到它。
# example data
month_no_list_svc_log = ["Nov", "Dec", "Jan", "Feb", "March", "April"]
event_count_by_month_list_svc_log = [10, 20, 30, 40, 50, 60]
fig, ax = plt.subplots(1,2, figsize = (10,4))
ax[0].plot(np.arange(len(month_no_list_svc_log)),event_count_by_month_list_svc_log)
# I do this to sort the months name the way I want it to
ax[0].set_xticks(np.arange(len(month_no_list_svc_log)))
ax[0].set_xticklabels(month_no_list_svc_log)
for i, txt in enumerate(event_count_by_month_list_svc_log):
# the code below generates an error
ax[0].annotate(txt, (month_no_list_svc_log[i],event_count_by_month_list_svc_log[i]))
我收到错误:
'NoneType'对象没有属性'seq'
答案 0 :(得分:1)
annotate
中的x坐标必须是您提供给plot
的x轴上的值。在那里,您使用了month_no_list_svc_log
中的月份索引,因此这与i
循环中的值for
相匹配。您也可以通过以下方式重复使用txt
,此处重命名为count
:
for i, count in enumerate(event_count_by_month_list_svc_log):
ax[0].annotate(count, (i, count))
顺便说一句:如果你想让你的x轴成为与你的y轴数据相同长度的arange
,你可以在调用图中放弃x轴参数:
ax[0].plot(event_count_by_month_list_svc_log)