Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use subplot and subplots of Matplotlib

Shulou Source: shulou.com Published: 2022-06-01 12:04:13 10月02日 Update

This article mainly introduces the Matplotlib subplot and subplots how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this Matplotlib subplot and subplots article, let's take a look at it.

The comparison begins:

Requirements: draw two subgraphs and display them on one line. The contents of the subgraphs are exactly the same.

Subplot Code:

Ax1 = plt.subplot ax1.scatter (positive ['X1'], positive [' X2'], sword50, marker='x', label='Positive') ax1.scatter (negative ['X1'], negative [' X2'], scurvie 50, marker='o', label='Negative') ax1.legend () # adding the image column is the top right-hand corner, indicating that ax2 = plt.subplot (1mezzo 2) ax2.scatter (positive ['X1'], positive [' X2'], slot50, marker='x') Label='Positive') ax2.scatter (negative ['X1'], negative [' X2'], saw50, marker='o', label='Negative') ax2.legend () # add the column is the point description in the upper right corner

Subplots Code:

Fig, ax = plt.subplots (figsize= (12Power8), ncols=2,nrows=1) # this method returns the drawing object and coordinate object ax,figsize is to set the length and width of the subimage (1200 Ax [0] .audter (positive ['X1'], positive [' X2'], sprinter 50, marker='x', label='Positive') ax [0] .accounter (negative ['X1'], negative [' X2'], slot50, marker='o', label='Negative') ax [0] .explanation () # adding the image column is the dot description in the upper right corner ax [1] .roomter (positive ['X1'], positive [' X2'], sprinter 50, marker='x' Label='Positive') ax [1] .roomter (negative ['X1'], negative [' X2'], saw50, marker='o', label='Negative') ax [1] .adding the figure column is the comparison result in the upper right corner:

You can see that both of them can achieve the function of drawing sub-images, but subplots helps us plan the artboard and returns an array of coordinate objects, while subplot can only return one coordinate object at a time. Subplots can directly specify the size of the artboard.

This is the end of the article on "how to use Matplotlib's subplot and subplots". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use Matplotlib's subplot and subplots". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Object that is content coordinates knowledge code artboard article exactly the same one line value function only size easy to operate array article method easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi OPPO Reno Apple Microsoft