in the use of Matplotlib drawing, if the diagram is larger, the drawing will block the line in the diagram, then you can use the following statements to draw the illustration to the outside of the diagram:

 plt.legend (bbox_to_anchor= (1.01, 1), loc=2, borderaxespad=0., handleheight=1.675) < / pre> 

, the statement can solve the illustration blocking the lines of the question. At the same time, it also introduces another problem: when savefig saves pictures, it can not save the picture completely, which will make the legend incomplete.

I feel that the reason is that the "graph" in the output (not including the illustration) is in the middle of the canvas, and when the output, the "graph" and the legend will be output, only the "graph" is in the middle, so the graph can only occupy the edge of the canvas, so that the output of the graph is incomplete.

solution, using the following statement to zoom the "graph" to the left to make space for the legend:

 fig.subplots_adjust (right=0.7) 

, and the size of the picture can be set with the following statements: (6.4, 4)

above this Matplotlib savefig save the size of the example is the size of the small editor to share all of the content, I hope to give you a reference, and also hope that you can support a lot of the script home.

This paper fixed link:http://www.script-home.com/matplotlib-savefig-an-example-of-saving-the-size-of-the-picture.html | Script Home | +Copy Link

Article reprint please specify:Matplotlib savefig an example of saving the size of the picture | Script Home

You may also be interested in these articles!