Solve the problem of overlapping graphics when drawing multiple pictures with matplotlib in python

  • 2021-07-10 20:16:44
  • OfStack

1. Solution: Use the function tight_layout ()

2. Specific usage


import matplotlib.pyplot as plt
 
fig = plt.figure()
 
 
'''
 Specific drawing program 
'''
 
fig.tight_layout()
fig.tight_layout()

Function: Make the horizontal and vertical coordinates of the sub-map more compact, mainly used to automatically adjust the size and spacing of the map area, so that all the drawings and their titles, coordinate axis labels, etc. can be completely displayed on the canvas without overlapping.

Parameters:

Pad: Used to set the distance between the edge of the drawing area and the edge of the canvas

w_pad: Used to set the horizontal distance between drawing areas

H_pad: Used to set the vertical distance between drawing areas

Examples:


fig.tight_layout(pad=0.4, w_pad=3.0, h_pad=3.0)

Recommend a good api query website: (English version)

https://devdocs.io/

Inside api documents cover most of the commonly used libraries, but also includes TensorFlow api documents, quite convenient.

In addition, the geek documents on the domestic w3cschool website are also OK (search the corresponding library name can be found), and some documents are Chinese.

https://www.w3cschool.cn/manual


Related articles: