Pandas plot, combine two plots

Currently, I have 3 plots that I draw in 2x2 dual slots. 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 4th subplot is empty, and I would like the 3rd part to occupy the entire last line.

I tried various combinations of axes for the third subtitle. How axes[1], axes[1:], axes[1,:]. But everything leads to an error.

So how can I achieve what I want?

+4
source share
1 answer

You can do it:

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 add_axes documentation

The coordinate rectI gave you is not very readable, but you can easily adjust it.

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

+2
source

Source: https://habr.com/ru/post/1651492/


All Articles