添加文字后,情节变得很小
我正在对欧洲电视网进行一些研究,多年来我绘制了一些国家的观点。 我最终将每个国家 /地区缩放,以便每年从0-100缩放得分。
我制作了一系列我使用有用的国家 /地区 。
然后,我使用以下代码来绘制和注释乌克兰:
plt.style.use("default")
# UKRAINE
fig, ax1 = plt.subplots(1, 1, sharey=False, figsize=(20, 10))
country = eurovision.loc[eurovision["Country"] == usefull[0]]
ax1.plot(country["Year"].astype(str), country["Scaled Grand Final Points"], label = "Ukraine", color = "#0057b7")
# ANNOTATING EVENTS
ax1.text(13.5, 50, " 2020 \n \n No contest because of COVID-19",
fontsize = 12, bbox=dict(facecolor='#ffd700', alpha=0.7))
ax1.text(13.5, 92, " WON IN 2022 \n \n A lot of sympathy votes because \n of the Russian War against Ukraine",
fontsize = 11, bbox=dict(facecolor='#ffd700', alpha=0.7))
ax1.text(4.8, 92, " WON IN 2016 \n \n Their song '1944' received lots of sympathy votes \n The song refers to the mass deportation of Crimean Tatars by Joseph Stalin",
fontsize = 11, bbox=dict(facecolor='#ffd700', alpha=0.7))
ax1.text(0.05, 1.7, " 2005 \n \n Low votes from eastern countries because \n of the pro-European Orange Revolution",
fontsize = 11, bbox=dict(facecolor='#ffd700', alpha=0.7))
ax1.text(4.5, 4.1, " 2009 \n \n Low votes from eastern countries due \n to an energy price conflict",
fontsize = 11, bbox=dict(facecolor='#ffd700', alpha=0.7))
ax1.set_title("Ukraine")
ax1.set_xlabel("Year")
ax1.set_ylabel("Total final points")
ax1.legend(bbox_to_anchor = (1, 0.1))
这很好,因为它输出了带有正确注释的不错的绘图,所以这很好 https://i.sstatic.net/8bc4b.png
但是,当我尝试做时在西班牙完全相同:
# SPAIN
fig, ax9 = plt.subplots(1, 1, sharey=False, figsize=(20, 10))
country = eurovision.loc[eurovision["Country"] == usefull[8]]
ax9.plot(country["Year"], country["Scaled Grand Final Points"], label = "Spain", color = "#FABD00")
ax9.text(1.3, 21, " 1960 \n \n Random event",
fontsize = 11, bbox=dict(facecolor='#FFF08', alpha=0.7))
ax9.set_title("Spain")
ax9.set_xlabel("Year")
ax9.set_ylabel("Total final points")
ax9.legend()
我将输出一个带有小注释框的超级小块。 https://i.sstatic.net/nrpez.png
我真的非常感谢大家帮助我找到修复程序!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您的数据,我获得了西班牙的正常尺寸图。我正在使用 python 3.8.9 和 matplotlib版本3.5.1 在Mac darwin内核版本20.6.0
/I.SSTATIC.NET/ZK2TE.JPG“ rel =” nofollow noreferrer 乌克兰与西班牙的代码中有一个区别,这使我的第一次尝试中没有出现文本和边界框。您在代码中缺少
astype(str)
ax99.plot
一旦我修复了这条线,我就将文字在剧情中得到了,就像乌克兰一样。
Using your data, I get a normal size plot for Spain. I am using python 3.8.9 and matplotlib version 3.5.1 on Mac Darwin Kernel Version 20.6.0
I notice one difference in your code for Ukraine vs Spain which made the text and bounding box not appear in my first attempt. You are missing
astype(str)
in your code forax9.plot
Once I fixed this line, I got the text in the plot - same like Ukraine.