简体   繁体   English

matplotlib savefig修剪图形

[英]matplotlib savefig trims the graph

I have a pretty simple pie chart in pyplot . 我在pyplot有一个非常简单的饼图。 The relevant code is this: 相关代码是这样的:

labels = 'SLoC', 'Violation'
sizes = [nrOfLines-totviols, totviols]
colors = ['#005fab', 'lightcoral']
explode = (0, 0.1)
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
        autopct='%1.1f%%', shadow=True,  startangle=90)
plt.axis('scaled')
plt.savefig("/usr/share/scaweb/static/plot-ratio.png", transparent=True, bbox_inches='tight', pad_inches=0)

In the picture, the pie chart is trimmed, which is wierd as the labels outside of the chart are still fully visible: 在图片中,饼图被裁剪,由于图表外的标签仍然完全可见,因此该饼图将被删除:

修整的饼图

I'm using matplotlib version 1.2. 我正在使用matplotlib 1.2版。

The problem you are having is that the circle is extending past the edges of the (axes that you can not see, but are there as the library sees the figure) and hence is getting clipped. 您遇到的问题是,圆弧超出了边缘的边缘(您看不见的轴,但是在库看到该图时轴就在那儿),因此被裁剪了。 This: 这个:

[__.set_clip_on(False) for __ in plt.gca().get_children()]

should fix it, but you might want to report this as a bug. 应该修复它,但是您可能希望将此报告为错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM