how to remove colorbar?

Dear all,

Is there a way to remove colorbar? axes.cla() clears only the region for map but not the colorbar.

Chao

···


Chao YUE
Laboratoire des Sciences du Climat et de l’Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex

Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16


Colorbars are a bit tricky. They are actually a subplot axes separate from your plotting axes. And I don’t think they are very easy to remove. You could do a “cbar.axes.cla()”, but that would still leave the “ticks”, tick labels and the colorbar label.

I am sure that there is a way to get to what you want, but it isn’t immediately obvious. If someone knows how to do it, maybe we should make that into a convenience function? Perhaps cbar.remove()?

Sorry I could not be more help.

Ben Root

···

On Mon, May 21, 2012 at 8:17 AM, Chao YUE <chaoyuejoy@…287…> wrote:

Dear all,

Is there a way to remove colorbar? axes.cla() clears only the region for map but not the colorbar.

Chao

Benjamin Root :

Colorbars are a bit tricky. They are actually a subplot axes separate from your plotting axes. And I don't think they are very easy to remove. You could do a "cbar.axes.cla()", but that would still leave the "ticks", tick labels and the colorbar label.

I am sure that there is a way to get to what you want, but it isn't immediately obvious.

Well, I tried with some success the following. Suppose the programme is:

from pylab import *
fig = figure()
ax = fig.add_subplot(111)
data = rand(250, 250)
cax = ax.imshow(data)
cbar = fig.colorbar(cax)
show()

Now, fig has two axes, the main, and the bar. The command

fig.delaxes(fig.axes[1])

gets rid of the bar and the ticks.
Is there anything wrong with that? Of course, I knew that fig.axes[1] was the bar, but finding it in a more complicated case should not be difficult.

All the best.

Jerzy Karczmarczuk

Thanks Jerzy. It works fine. I may return to this topic for more discussion
later.

chao

Jerzy Karczmarczuk-2 wrote:

···

Benjamin Root :

Colorbars are a bit tricky. They are actually a subplot axes separate
from your plotting axes. And I don't think they are very easy to
remove. You could do a "cbar.axes.cla()", but that would still leave
the "ticks", tick labels and the colorbar label.

I am sure that there is a way to get to what you want, but it isn't
immediately obvious.

Well, I tried with some success the following. Suppose the programme is:

from pylab import *
fig = figure()
ax = fig.add_subplot(111)
data = rand(250, 250)
cax = ax.imshow(data)
cbar = fig.colorbar(cax)
show()

Now, fig has two axes, the main, and the bar. The command

fig.delaxes(fig.axes[1])

gets rid of the bar and the ticks.
Is there anything wrong with that? Of course, I knew that fig.axes[1]
was the bar, but finding it in a more complicated case should not be
difficult.

All the best.

Jerzy Karczmarczuk

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://old.nabble.com/how-to-remove-colorbar--tp33882320p33892056.html
Sent from the matplotlib - users mailing list archive at Nabble.com.