我正在尝试标记四个图中每个图中的所有点。如图所示,我设法在最后一个点上标记了所有点:
但是,我尝试了几种组合,但无法使用。我当前的脚本是这个。请问有人能帮我忙吗?
plt.rcParams['figure.figsize'] = (10, 8)
f, ((ax5, ax6), (ax7, ax8)) = plt.subplots(2, 2)
ax5.scatter(large.total_tax, large.id_inf)
ax5.set_title("Large Firms")
ax6.scatter(medium.total_tax, medium.id_inf)
ax6.set_title("Medium Firms")
ax7.scatter(small.total_tax, small.id_inf)
ax7.set_title("Small Firms")
ax8.scatter(micro.total_tax, micro.id_inf)
ax8.set_title("Micro Firms")
for i, ciiu_4n1 in enumerate(micro.ciiu_4n1):
ax8 = plt.annotate(ciiu_4n1, [micro.total_tax[i], micro.id_inf[i]])
答案 0 :(得分:1)
您可以使用另一个for循环遍历轴,并使用ax.annotate
来确保绘制到正确的轴:
for ax in [ax5, ax6, ax7, ax8]:
for i, ciiu_4n1 in enumerate(micro.ciiu_4n1):
ax.annotate(ciiu_4n1, [micro.total_tax[i], micro.id_inf[i]])
如果每个图使用不同的数据集,那么解决方案是对每个轴进行初始循环,如Bazingaa的答案所示
答案 1 :(得分:0)
尝试类似的方法,如果可行,请在下面添加评论。不是,我会删除我的答案
for i, ciiu_4n1 in enumerate(micro.ciiu_4n1):
ax8.annotate(ciiu_4n1, [micro.total_tax[i], micro.id_inf[i]])
for i, ciiu_4n1 in enumerate(small.ciiu_4n1):
ax7.annotate(ciiu_4n1, [small.total_tax[i], small.id_inf[i]])
for i, ciiu_4n1 in enumerate(medium.ciiu_4n1):
ax6.annotate(ciiu_4n1, [medium.total_tax[i], medium.id_inf[i]])
for i, ciiu_4n1 in enumerate(large.ciiu_4n1):
ax5.annotate(ciiu_4n1, [large.total_tax[i], large.id_inf[i]])