Friday, May 27, 2022
HomeMachinelearningWhat is subplot in matplotlib

What is subplot in matplotlib

What is subplot in matplotlib

In previous blog post we have discussed about, different ways to plot like,

1) Functional method 2) Object-Oriented method.

If you haven’t seen the Functional method Click here to read more.

Now let’s discuss how to plot using the Object-Oriented method.

But before that let’s design our plot using “fontdict” parameter.

How to change the font size on a matplotlib plot?

fontTitle={‘family’ : ‘serif’,’weight’ : ‘bold’,’size’ : 40,’color’:’green’}
fontLabel={‘family’ : ‘serif’,’weight’ : ‘bold’,’size’ : 25,’color’:’orange’}
plt.xlabel(‘Test X’,fontdict =fontLabel)
plt.ylabel(‘Test Y’,fontdict =fontLabel)
plt.title(‘Test Title’,fontdict =fontTitle)

Here we have used the family, weight, size, color as an argument and perform some kind of design.

How to control the position and size of axes?

To control the size and position we have “figure ()”. The plot will look the same as we had drawn in our previous blog but here, we have used sort of the object-oriented method.

fig=plt.figure(), it will generate the figure object and then we set certain axes to it.

The axes, set using the list of argument. 4 arguments are required to set the axes. [Left, Bottom, Width, Height], it ranges from 0 to 1. A kind of the percentage of the blank canvas you want. In short, we control the position and size of the axes.

To understand in detail, how this 4-parameter works check out the image below you will get the proper idea.

How to plot two set of figures in one canvas?

We have already done this task in previous post (Click here to read), same kind of operation is performed here. Have a look on the above image and you get the idea.

How to add title to entire canvas?

To add the title or label to entire canvas or figure or plot we uses “subtitle()” function.

fig.suptitle(‘All in one’).

How facecolor works in our canvas?

Using facecolor we can change the background of the canvas without changing the facecolor of the entire plot.

fig.set_facecolor(“red”)

What is difference between “.figure()” and “.subplot()”? And

How to create subplots in matplotlib?

Let’s understand is simple word, subplot, will internally works with “add_axes”. Like you just need to specify the number of rows and column, and you are good to go.

While, when we work with the “figure()”, manually we have work.

To create the subplot, we need to use “fig,ax1=plt.subplots(nrows=1, ncols=2)” instead of figure. It works as axes manager on top of “plt.figure()”. It required arguments like number of rows and columns you want to plot on canvas.

Ax1: – is a list of matplotlib axes.

You can also use the index and work with ax1.

Conclusion: Using figure and subplot method or function you can design your canvas.If you have any query you can write the comment down below.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments