Make more than one chart in same IPython Notebook cell


Question

I have started my IPython Notebook with

ipython notebook --pylab inline

This is my code in one cell

df['korisnika'].plot()
df['osiguranika'].plot()

This is working fine, it will draw two lines, but on the same chart.

I would like to draw each line on a separate chart. And it would be great if the charts would be next to each other, not one after the other.

I know that I can put the second line in the next cell, and then I would get two charts. But I would like the charts close to each other, because they represent the same logical unit.

1
70
5/11/2013 7:57:14 AM

Accepted Answer

Make the multiple axes first and pass them to the Pandas plot function, like:

fig, axs = plt.subplots(1,2)

df['korisnika'].plot(ax=axs[0])
df['osiguranika'].plot(ax=axs[1])

It still gives you 1 figure, but with two different plots next to each other.

74
5/6/2013 6:18:52 AM

You can also call the show() function after each plot. e.g

   plt.plot(a)
   plt.show()
   plt.plot(b)
   plt.show()

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon