Hi,
I am trying to plot a colorbar next to each subplot in a figure. In the
following example, I create two figures. In the second figure, I try to add the
colorbars. Is there a way to show the colorbar next to each subplot. The way I
did it, all the colorbars appear next to the last subplot, take away space from
it, and all are plotted using the "jet" colormap.
Unfortunately, I am not sure how to do this better, and would appreciate hints.
import numpy as np
import matplotlib.pylab as plt
def main():
# four subplots, no colorbar, so far so good
f, axarr = plt.subplots(2, 2)
axarr[0, 0].imshow(np.random.rand(5,5)*10)
axarr[0, 1].imshow(np.random.rand(5,5))
axarr[1, 0].imshow(np.random.rand(5,5)*100)
axarr[1, 1].imshow(np.random.rand(5,5)*1000)
plt.show()
# four subplots, four colorbars
f, axarr = plt.subplots(2, 2)
a = axarr[0, 0].imshow(np.random.rand(5,5)*10)
cbar1 = f.colorbar(a, cmap='jet')
b = axarr[0, 1].imshow(np.random.rand(5,5))
cbar2 = f.colorbar(b, cmap='Reds')
c = axarr[1, 0].imshow(np.random.rand(5,5)*100)
cbar2 = f.colorbar(c, cmap='Blues')
d = axarr[1, 1].imshow(np.random.rand(5,5)*1000)
cbar2 = f.colorbar(d, cmap='Greens')
plt.show()
if __name__ == '__main__':
main()
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users