1

From reading online (such as here, although they import pylab rather than pyplot, from which I have the same result), when using pyplot's show method, it should automatically rescale the figure to include the legend if it's been placed outside the main graph; however, that does not appear to be happening with my code.

Does anyone have any ideas about how to do this? Thanks.

# Cut down example of graph drawing, with cut-off legend

plt.xlim([0,1])
plt.ylim([0,1])

line_x = line[t2][0::2]
line_y = line[t2][1::2]

plt.plot(line_x, line_y, label="Line")

plt.grid("on")
plt.tight_layout()
plt.legend(bbox_to_anchor=(1.01, 0.5), loc="center left")

plt.show()

Graph with cut-off legend

AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27
  • I think you have to [shrink](http://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot) your plot a little bit – Crispin Feb 27 '17 at 11:12
  • also, [this](http://stackoverflow.com/questions/10101700/moving-matplotlib-legend-outside-of-the-axis-makes-it-cutoff-by-the-figure-box) – Crispin Feb 27 '17 at 11:19
  • Can you give a reference to *"from reading online"*? – ImportanceOfBeingErnest Feb 27 '17 at 12:07
  • This is one example I was following, where the show() sizes things (they use pylab rather than pyplot, but I get the same result when swapping them out): http://jb-blog.readthedocs.io/en/latest/posts/0012-matplotlib-legend-outdide-plot.html . It's not the only one I've seen, but I'd rather not list a number of links in a comment. – AdmiralJonB Feb 27 '17 at 12:11
  • So the difference is that the link uses a Notebook, e.g. jupyter with `%matplotlib inline` turned on, in which case the shown figure is automatically resized. But it also states this to be not the case for saving the figure. – ImportanceOfBeingErnest Feb 27 '17 at 12:21

0 Answers0