Merge colorbars from imshow and contour

Hi,

in a case similar to matplotlib-0.87.7/examples/contour_demo.py (figure 4), would it be possible to merge to two colorbars (a continuous one from imshow, a discrete one from contour) into a single colorbar? Indeed, in that case, the two colorbars are mostly redundant.

Cheers.

···

--
             / \ , ,
   _._ _ |oo| _ / \__/ \
  _|||| ((/ () \)) / \ Yannick COPIN (o:>* Doctus cum libro
  >>>>>/| ( ==== ) |oo| Institut de physique nucleaire de Lyon
   \____/ _`\ /'_ / \ (IN2P3 - France)
   / /.-' /\<>/\ `\.( () )_._ Tel: (33/0) 472 431 968
   > ` / \/ \ /`'--'////) http://snovae.in2p3.fr/ycopin/
    \__,-'`| |. |\/ |/\/\|"\"` AIM: YcCopin ICQ: 236931013
       jgs | |. | \___/\___/
           > >. | | |

Yannick Copin wrote:

Hi,

in a case similar to matplotlib-0.87.7/examples/contour_demo.py (figure 4), would it be possible to merge to two colorbars (a continuous one from imshow, a discrete one from contour) into a single colorbar? Indeed, in that case, the two colorbars are mostly redundant.

Cheers.

Yes, lines can be superimposed on a continuous colorbar. The demo is not ideal; I was mainly showing that one could use two colorbars for two different things. I have changed the contourf_demo.py in svn to include an example of a merged colorbar. Maybe I will change contour_demo.py later to make it an illustration of having colorbars for completely different fields, so it won't look so pointless as it does now.

Eric

Hi,

Eric Firing wrote:

in a case similar to matplotlib-0.87.7/examples/contour_demo.py (figure 4), would it be possible to merge to two colorbars (a continuous one from imshow, a discrete one from contour) into a single colorbar? Indeed, in that case, the two colorbars are mostly redundant.

Yes, lines can be superimposed on a continuous colorbar. The demo is not ideal; I was mainly showing that one could use two colorbars for two different things. I have changed the contourf_demo.py in svn to include an example of a merged colorbar. Maybe I will change contour_demo.py

Thanks! For those of you interested to know whitout having to look at SVN repository, you need to use colorbar method add_lines:

X, Y = meshgrid(linspace(-3,3,11),linspace(-3,3,11))
Z = bivariate_normal(X, Y, 1.0, 1.0, 1.0, 1.0)

lev = linspace(Z.min(),Z.max(),11)[1:-1]

im = imshow(Z, extent=[-3,3,-3,3])
cl = contour(X,Y,Z, lev, colors='k')

cb = colorbar(im)
cb.add_lines(cl)

Cheers.

···

--
             / \ , ,
   _._ _ |oo| _ / \__/ \
  _|||| ((/ () \)) / \ Yannick COPIN (o:>* Doctus cum libro
  >>>>>/| ( ==== ) |oo| Institut de physique nucleaire de Lyon
   \____/ _`\ /'_ / \ (IN2P3 - France)
   / /.-' /\<>/\ `\.( () )_._ Tel: (33/0) 472 431 968
   > ` / \/ \ /`'--'////) http://snovae.in2p3.fr/ycopin/
    \__,-'`| |. |\/ |/\/\|"\"` AIM: YcCopin ICQ: 236931013
       jgs | |. | \___/\___/
           > >. | | |