I want to plot 5 data frames in a 2 by 3 setting (i.e. 2 rows and 3 columns). This is my code: However there is an extra empty plot in the 6th position (second row and third column) which I want to get rid of it. I am wondering how I could remove it so that I have three plots in the first row and two plots in the second row.
import matplotlib.pyplot as plt fig, axes = plt.subplots(nrows=2, ncols=3) fig.set_figheight(8) fig.set_figwidth(15) df[2].plot(kind='bar',ax=axes[0,0]); axes[0,0].set_title('2') df[4].plot(kind='bar',ax=axes[0,1]); axes[0,1].set_title('4') df[6].plot(kind='bar',ax=axes[0,2]); axes[0,2].set_title('6') df[8].plot(kind='bar',ax=axes[1,0]); axes[1,0].set_title('8') df[10].plot(kind='bar',ax=axes[1,1]); axes[1,1].set_title('10') plt.setp(axes, xticks=np.arange(len(observations)), xticklabels=map(str,observations), yticks=[0,1]) fig.tight_layout()
Set the figure size and adjust the padding between and around the subplots. Plot line1 and line2 using plot() method. Pop the second line and remove it.
We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots. The parameters wspace and hspace specify the space reserved between Matplotlib subplots.
Often you may use subplots to display multiple plots alongside each other in Matplotlib. Unfortunately, these subplots tend to overlap each other by default. The easiest way to resolve this issue is by using the Matplotlib tight_layout() function.
Try this:
fig.delaxes(axes[1][2])
A much more flexible way to create subplots is the fig.add_axes()
method. The parameters is a list of rect coordinates: fig.add_axes([x, y, xsize, ysize])
. The values are relative to the canvas size, so an xsize
of 0.5
means the subplot has half the width of the window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With