0

I am trying to put together four subplots that are made using pandas.plot() method. When plotting separately, they show up fine as below:

enter image description here

But once I started using subplot, it became this:

enter image description here

I know there might be something to do with either naming the plot objects or using pyplot instead of the pandas .plot method, but couldn't figure out after tried different things. Any hint is appreciated.

George Liu
  • 3,601
  • 10
  • 43
  • 69

2 Answers2

2

Use the ax argument.

df = pd.DataFrame({"foo":[4,5,6], "bar":[1,4,2]})

f, (ax1, ax2) = plt.subplots(2, 1, figsize=(4,3))

df.foo.plot(ax=ax1)
df.bar.plot(ax=ax2)

plot

andrew_reece
  • 20,390
  • 3
  • 33
  • 58
1

You can try also in this way for example:

fig = plt.figure()
ax = fig.add_subplot(221)
plt.plot(x,y)

ax = fig.add_subplot(222)
plt.plot(x,z)
...

plt.show()
Joe
  • 12,057
  • 5
  • 39
  • 55