Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas plot, combine two plots

Currently I have 3 plots that I am plotting in the 2x2 subplots. It looks like this:

fig, axes = plt.subplots(nrows=2, ncols=2)
df1.plot('type_of_plot', ax=axes[0, 0]);
df2.plot('type_of_plot', ax=axes[0, 1]);
df3.plot('type_of_plot', ax=axes[1, 0]);

The 4-th subplot is empty, and I would like the 3-rd one to occupy the whole last row.

I tried various combinations of axes for the third subplot. Like axes[1], axes[1:], axes[1,:]. But everything results in the error.

So how can I achieve what I want?

like image 992
Salvador Dali Avatar asked Oct 29 '22 22:10

Salvador Dali


1 Answers

You can do this :

import matplotlib.pyplot as plt

fig=plt.figure()
a=fig.add_axes((0.05,0.05,0.4,0.4)) # number here are coordinate (left,bottom,width,height)
b=fig.add_axes((0.05,0.5,0.4,0.4))
c=fig.add_axes((0.5,0.05,0.4,0.85))

df1.plot('type_of_plot', ax=a);
df2.plot('type_of_plot', ax=b);
df3.plot('type_of_plot', ax=c);

plt.show()

see also the documentation of add_axes

The rect coordinate I gave you are not very readable, but you can easily adjust it.

EDIT: Here is what I got : enter image description here

like image 70
CoMartel Avatar answered Nov 15 '22 06:11

CoMartel