Peter Rowat
2015-02-20 07:10:55 UTC
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
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