Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to position subplots next to each other

I am trying to position two subplots next to each other (as opposed to under each other). I am expecting to see [sp1] [sp2]
Instead, only the second plot [sp2] is getting displayed.

from matplotlib import pyplot

x = [0, 1, 2]

pyplot.figure()

# sp1
pyplot.subplot(211)
pyplot.bar(x, x)

# sp2
pyplot.subplot(221)
pyplot.plot(x, x)

pyplot.show()
like image 806
Axel Avatar asked Oct 23 '09 23:10

Axel


2 Answers

The 3 numbers are rows, columns, and plot #. What you're doing is respecifying the number of columns in your second call to subplot, which in turn changes the configuration and causes pyplot to start over.

What you mean is:

subplot(121)  # 1 row, 2 columns, Plot 1
...
subplot(122)  # 1 row, 2 columns, Plot 2
like image 181
Adam Bard Avatar answered Oct 05 '22 04:10

Adam Bard


from matplotlib import pyplot

x = [0, 1, 2]

pyplot.figure()

# sp1
pyplot.subplot(121)
pyplot.bar(x, x)

# sp2
pyplot.subplot(122)
pyplot.plot(x, x)

pyplot.show()
like image 27
Axel Avatar answered Oct 05 '22 05:10

Axel