Python data Analysis matplotlib sets the spacing method for multiple subgraphs

  • 2020-12-09 00:54:44
  • OfStack

Note that simple knowledge of Python data analysis is essential to understand this, and simple use of matplotlib is essential!

Case 1:


plt.subplot(221) #  The first 1 The left 

plt.subplot(222) #  The first 1 The right 

plt.subplot(212) #  The first 2 The entire line 

plt.title( ' xxx')

plt.tight_layout() # Set the default spacing 

Example 2:


for i in range(25):

plt.subplot(5,5,i+1)

plt.tight_layout()

Example 3:


#  Set the size of the drawing board 
plt.figure(figsize=(12,16))
#  To establish 1 Loop, output picture 
for i,data in enumerate(xtest[:100]):
#   Set the subgraph and output each subgraph to the corresponding position 
 plt.subplot(10,10,i+1)
#   Output the image, the data taken out must be processed before output, for example 8*8
 plt.imshow(data.reshape(8,8))
#   The title of the test and the actual title are printed 
 plt.title('C:'+str(y_[i])+'\nT:'+str(ytrue[:100][i]),size=20)
#   Turn off the x y Scale of the shaft 
 plt.axis('off')
#   Adjust the distance between each subgraph 
 plt.tight_layout()

Related articles: