Le jeudi 19 février 2015 à 23:10 -0800, Peter Rowat a écrit :
> 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
cax is not the Axes containing the image, but the image itself. It seems
that you want to "steal" some space to the first subplot so:
fig, (ax1, ax2,ax3) = plt.subplots(3,1)
im = ax1.imshow(bighistT, extent=myextent, cmap=cm.coolwarm,
aspect=myaspect, interpolation='nearest')
ax1.set_title("Dummy title")
cbar = fig.colorbar(im, ax=ax1)
or you can also create a new Axes between ax1 and ax2, and tell
colorbar() to put the Colorbar into (with the cax keyword argument)
See
http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.colorbar
--
Fabrice
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users