Astro_Dart
Astro_Dart

Reputation: 305

Equal Height subplots in matplotlib

I have a script that generates two plots side by side of two aspects of the same quantity. It's fairly long, so this is only the relevant (I believe) portion. The left hand plot is called by the function "plot_shearsticks2"

Depending on what data I'm plotting, the left hand plot may have slightly different dimensions, but I would like the two to have the same height always, and if the left hand one is wider, that's fine (and usually it ought to). Here is the relevant portion:

    import matplotlib.pyplot as plt

    figr = plt.figure(i,figsize=(11, 5))

    fig=figr.add_subplot(121,aspect='equal')
    figr.subplots_adjust(wspace=0.3)
    shearplot = plot_shearsticks2(cat.data,[imoments[0],imoments[1],imoments[2],imoments[3],imoments[4]],scale_factor,'-k')     

    fig=figr.add_subplot(122,aspect='equal')
    figr = plt.figure(i,figsize=(11, 5))

And below this, there are some instructions for making the right hand plot, but nothing that seems to indicate anything about how tall it is. Tinkering with the options in add_subplot, doesn't seem to have any effect -- the left hand side is always smaller for some reason. Any idea how to make them equal heights?

Upvotes: 1

Views: 1409

Answers (2)

Astro_Dart
Astro_Dart

Reputation: 305

Ended up redoing everything with GridSpec, and specifying plot heights with gs = gridspec.GridSpec(1,2,height_ratios=[1],width_ratios=[ratioxy,1]), having defined ratioxy with ratioxy=widthx/heighty

Upvotes: 2

ssm
ssm

Reputation: 5373

I always find it easier to ise the axes funciton. For example:

import pylab as pl
pl.figure(figsize=(4,3))
pl.axes([0.2, 0.2, 0.75, 0.35 ])
pl.axes([0.2, 0.55, 0.75, 0.35 ])

This way you have the ability to control the axis properties very accurately, and even partially/fully overlay one over the other. This gives you significant advantage over the subplot function.

Upvotes: 1

Related Questions