简体   繁体   中英

matplotlib savefig trims the graph

I have a pretty simple pie chart in 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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