Peter,

I think that you want
cax = ax1.imshow(…)
cbar = fig.colorbar(cax,ax=ax1) # Where the ax keyword tells the colorbar which 
axes to steal space from. [1]

If you want the colorbar to be to the right of the first axes, and have the 
second and third axes line up with the first, then you need to create your own 
axes instance [2] {cbarax = fig.add_axes([…]) } for the colorbar and give that 
instance to the cax keyword of fig.colorbar (without an ax keyword). [1]

Also, I wouldn’t refer to the object returned by imshow as cax, as that is 
confusing when looking at the possible arguments of fig.colorbar.  I would call 
the image object im or something similar.  

-Sterling

[1] http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.colorbar
[2] http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.add_axes

On Feb 19, 2015, at 11:10PM, Peter Rowat <pe...@pelican.ucsd.edu> wrote:

> I apologize for asking such a trivial question, but I’ve spent a long time 
> trying to fix this:
> 
> I have a large 2D array that displays as an image, with a colorbar on the 
> side.
> I also display 2 curves on top of the image. i.e. in same axes.
> The following code does it:
> 
>     fig,ax = plt.subplots()
>     cax = ax.imshow(bighistT, extent=myextent, cmap = cm.coolwarm, aspect = 
> myaspect,\
>         interpolation='nearest')
>     ax.set_title("Dummy title")
>     # Add colorbar
>     cbar = fig.colorbar(cax)
>     ax.set_ylabel('mV')
> 
>     ax.plot(emtrate, emrate, '.r')                  #curve 1
>     ax.plot(tt, rate*50 - 25.0, '-k', linewidth=3)  #curve 2
> 
>     plt.show()
> ========
> IN FACT,
> I want the curves in separate axes, below the image while the colorbar 
> remains immediately to the right
> of the image.
> 
> I've tried many minor variations, for way over an hour..
> I've looked at demos, read about colorbar in several different parts of 
> matplotlib docs...
> 
> Can someone help?? .... Either the colorbar is next to the last plot, or else 
> I
> get an error.
> 
> Here is code that I've tried: It puts the colorbar in the wrong place, and in 
> addition the image size
> is very small while the ax2 and ax3 curve plots are much wider. 
> I want the image and the second 2 plots the same width.
> 
> 
>     fig, (ax1, ax2,ax3) = plt.subplots(3,1)
>     cax = ax1.imshow(bighistT, extent=myextent, cmap = cm.coolwarm, aspect = 
> myaspect,\
>         interpolation='nearest')
>     ax1.set_title("Dummy title")
>     # Add colorbar
> #   cbar = fig.colorbar(cax)  # this places the colorbar next to the third 
> subplot
>     plt.colorbar(cax)         # so does this
>     ax1.set_ylabel('mV')
>     ax2.plot(emtrate, emrate, '.r')
>     ax3.plot(tt, rate*50 - 25.0, '-k', linewidth=3)
> 
>     plt.show()
> Thanks for any help,
> 
> Peter
> Save our in-boxes! http://emailcharter.org 
> 
> 
> 
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk_______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to