[SciPy-User] matplotlib woes

Tony S Yu tsyu80@gmail....
Tue Jun 8 13:48:28 CDT 2010

On May 28, 2010, at 9:29 AM, Thøger Emil Juul Thorsen wrote:

> Hello SciPy list; 
> For my thesis I have an image which is also a spectrum of an object. I
> want to plot the image using imshow along with a data plot of the
> intensity, as can be seen on http://yfrog.com/0tforscipylistp .
> My questions are 2:
> 1) imshow() sets the ticks on the two upper subplots as pixels
> coordinates. What I want to show as tick labels on my x-axis is the
> wavelength coordinates of the lower plot on the upper images (since
> there is a straightforward pixel-to-wavelength conversion). I have
> googled everywhere but can't seem to find a solution, is it possible?
> 2) Is there any possible way to make the subplots layout look a bit
> nicer? Ideally to squeeze the two upper plots closer together and
> stretch the lower plot vertically, or at least to make the two upper
> subplots take up an equal amount of space?
> Best regards; 
> Emil, python-newb and (former) IDL-user, 
> Master student of Astrophysics at the University of Copenhagen, 
> Niels Bohr Instutute.

Hey Emil,

1) You should try the `extent` argument in `imshow`. From the docs for imshow:

*extent*: [ None | scalars (left, right, bottom, top) ]
        Data limits for the axes.  The default assigns zero-based row,
        column indices to the *x*, *y* centers of the pixels.

For example:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(0, 2*np.pi)
>>> Y = np.sin([x, x])
>>> plt.imshow(Y, extent=[0, 2*np.pi, 0, 1])

2) If you're plotting interactively, you can configure the subplots using the command on the toolbar (3rd from right). If you want to add the adjustment to your script use `subplots_adjust`. For example,

>>> plt.subplots_adjust(hspace=0.1)

where "hspace" is the spacing (height) between subplots. Of course, change the value of hspace to suit your needs. I'm actually surprised there's so much spacing between your subplots, so I suspect you may be doing something strange in your plot script. If subplots_adjust doesn't work it may be helpful to see your plot script, BUT....

Please move this discussion to the matplotlib-users list (https://lists.sourceforge.net/lists/listinfo/matplotlib-users), if you have further questions or want to follow-up on this question. It's more appropriate for matplotlib-specific questions.


More information about the SciPy-User mailing list