[英]fig.savefig Exporting as Blank
This code ultimately outputs an all white.png file.这段代码最终会输出一个全白的.png 文件。 The image renders properly in Jupyter Notebooks.图像在 Jupyter Notebooks 中正确呈现。 What am I doing wrong?我究竟做错了什么?
fig, ax = plt.subplots()
fig = plt.figure(figsize=[70, 70])
size = 1
ax.set_title('Groups, 2019 vs 2020')
colours = ['red', 'darkorange', 'lawngreen', 'dodgerblue', 'mediumpurple', 'deeppink']
labels = ['tv film', 'comms', 'health', 'ent other', 'elections', 'misc']
data = [tv_film_mean_2020, comms_mean_2020,
health_mean_2020, ent_other_mean_2020,
elections_mean_2020, misc_mean_2020]
ax.pie(x = data, radius=4,labels=labels, labeldistance=.9, pctdistance=.85,colors=colours, wedgeprops=dict(width=size, edgecolor='black'), autopct='%1.1f%%')
sub_colours = ['red', 'darkorange', 'lawngreen', 'dodgerblue', 'mediumpurple', 'deeppink']
sub_labels = ['tv film(2019)', 'comms(2019)', 'health(2019)',
'ent other(2019)', 'elections(2019)', 'misc(2019)']
sub_data = [tv_film_mean_2019, comms_mean_2019,
health_mean_2019, ent_other_mean_2019,
elections_mean_2019, misc_mean_2019]
ax.pie(x = sub_data, radius=(3), pctdistance=.72,labels=sub_labels, labeldistance=0.8, colors=sub_colours, rotatelabels=True, wedgeprops=dict(width=size, edgecolor='black'), autopct='%1.1f%%')
ax.set(aspect="equal")
fig.savefig(f'../output_graphs/Group_Nested_agg.png',bbox_inches='tight',transparent = False,dpi=100)
plt.show()
you 2nd line reassigns the variable fig
to a new plot that does not have ax
on it (which you then add all your data to).您第二行将变量fig
重新分配给一个新的 plot,它上面没有ax
(然后您将所有数据添加到其中)。 I don't think you need or want the line:我认为您不需要或不想要这条线:
fig = plt.figure(figsize=[70, 70])
You should be able to add the figsize=[70, 70]
to the first line, eg:您应该能够将figsize=[70, 70]
添加到第一行,例如:
fig, ax = plt.subplots(figsize=[70, 70])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.