निम्नलिखित आलेख पढ़ना, मैंने साजिश के बाहर एक किंवदंती डालने में कामयाब रहे।साजिश के बाहर एक पौराणिक कथा के साथ Matplotlib savefig
कोड:
import matplotlib.pyplot as pyplot
x = [0, 1, 2, 3, 4]
y = [xx*xx for xx in x]
fig = pyplot.figure()
ax = fig.add_subplot(111)
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width*0.8, box.height])
ax.plot(x, y)
leg = ax.legend(['abc'], loc = 'center left', bbox_to_anchor = (1.0, 0.5))
#pyplot.show()
fig.savefig('aaa.png', bbox_inches='tight')
pyplot.show()
प्रदर्शित करता है यह बाहर एक पौराणिक कथा के साथ सही साजिश। लेकिन जब मैं इसे fig.savefig()
के साथ फ़ाइल के रूप में सहेजता हूं, तो किंवदंती को छोटा कर दिया जाता है।
कुछ Googling मुझे इस तरह के bbox_extra_artists=[leg.legendPatch]
या bbox_extra_artists=[leg]
savefig()
को जोड़ने के रूप में workarounds पता चलता है, लेकिन न तो काम किया।
ऐसा करने का सही तरीका क्या है? Matplotlib संस्करण 0.9 9.3 है।
धन्यवाद।
(मैं देख रहा हूँ इस पुराने धागा है, लेकिन यह गूगल का पहला सदस्य है) वहाँ एक है savefig के लिए कलाकारों को शामिल करके बेहतर समाधान: http://stackoverflow.com/questions/10101700/moving-matplotlib-legend-outside-of-the-axis-makes-it-cutoff-by-the-figure-box – Alleo