views:

113

answers:

2

if I have a series of subplots with one column and many rows, i.e.:

plt.subplot(4, 1, 1) # first subplot
plt.subplot(4, 1, 2) # second subplot
# ...

how can I adjust the height of the first N subplots? For example, if I have 4 subplots, each on its own row, I want all of them to have the same width but the first 3 subplots to be shorter, i.e. have their y-axes be smaller and take up less of the plot than the y-axis of the last plot in the row. How can I do this?

thanks.

+1  A: 

Use the AxesGrid toolkit.

vtorhonen
Could you show an example that's not image based? I'm not sure how to apply it to arbitrary plots based on the example in the docs
Note: I don't want to do this by sharing axes if possible -- I'd like to just make the top 3 rows take up less than the last row subplot. For example, the first three might take up 50% of the figure, while the last might take up the remaining 50%
I can't find the bit of code where I used AxesGrid for such plotting. However, another option is to use [axes](http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axes) instead of subplots. Axes allows arbitrary positioning for the subplot.
vtorhonen
+1  A: 

There are multiple ways to do this. The most basic (and least flexible) way is to just call something like:

import matplotlib.pyplot as plt
plt.subplot(6,1,1)
plt.subplot(6,1,2)
plt.subplot(6,1,3)
plt.subplot(2,1,2)

Which will give you something like this: Unequal Subplots

However, this isn't very flexible. If you're using matplotlib >= 1.0.0, look into using GridSpec. It's quite nice, and is a much more flexible way of laying out subplots.

Joe Kington