Thread Subject: colorbar title

Subject: colorbar title

From: Christopher Hummersone

Date: 30 Jun, 2008 16:09:02

Message: 1 of 13

Hi all,

Does anyone know how to add a title to a colorbar? It
should be something like 'xlabel' except the text would be
to the right of the bar; alas no such property seems to
exist for the colorbar.

Thanks,

Chris

Subject: colorbar title

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 Jun, 2008 16:42:19

Message: 2 of 13

In article <g4b0eu$qbm$1@fred.mathworks.com>,
Christopher Hummersone <wheely_chairs@hotmail.com> wrote:

>Does anyone know how to add a title to a colorbar? It
>should be something like 'xlabel' except the text would be
>to the right of the bar; alas no such property seems to
>exist for the colorbar.

Once you have the handle of the colorbar axes, you can get()
the YLabel property, which will be a text() object. You can then
set the String property of that. You would probably have some
difficulty with the orientation of the text displayed, though.

If it is acceptable to have the title of the colorbar appear
over the colorbar, then get() the Title property of the colorbar
axes, which will be a text() object that you can set the String
property of.
--
   "No one has the right to destroy another person's belief by
   demanding empirical evidence." -- Ann Landers

Subject: colorbar title

From: Christopher Hummersone

Date: 30 Jun, 2008 18:35:03

Message: 3 of 13

Thanks for your reply Walter. However, I'm a little
confused. Having not used handles much (just adding
gca/gcf etc when required) I'm at a bit of a loss on how to
do this. If I enter:

cbar_axes = colorbar('peer',gca,...etc.);
get(cbar_axes)

I get an "invalid handle object" error message. Now I
appreciate that I'm probably doing something stupid, so
could you please point me in the right direction!?

Many thanks,

Chris

Subject: colorbar title

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 Jun, 2008 19:25:57

Message: 4 of 13

In article <g4b90m$4pv$1@fred.mathworks.com>,
Christopher Hummersone <wheely_chairs@hotmail.com> wrote:

>If I enter:

>cbar_axes = colorbar('peer',gca,...etc.);
>get(cbar_axes)

>I get an "invalid handle object" error message.

That code outline -looks- correct to me. Which Matlab version are
you using? In R2007a:

>> figure; plot(rand(5,99)); t = colorbar('peer',gca); get(t)

    ActivePositionProperty: 'position'
                      ALim: [0.1 10]
                  ALimMode: 'auto'
         AmbientLightColor: [1 1 1]
                       Box: 'on'
            CameraPosition: [0.5 33 9.16025403784439]
        CameraPositionMode: 'auto'
              CameraTarget: [0.5 33 0.5]
          CameraTargetMode: 'auto'
            CameraUpVector: [0 1 0]
        CameraUpVectorMode: 'auto'
           CameraViewAngle: 6.60861036031192
       CameraViewAngleMode: 'auto'
                      CLim: [1 64]
                  CLimMode: 'auto'
                     Color: [1 1 1]
              CurrentPoint: [2x3 double]
                ColorOrder: [7x3 double]
           DataAspectRatio: [3 64 1]
       DataAspectRatioMode: 'auto'
                  DrawMode: 'normal'
                 FontAngle: 'normal'
                  FontName: 'Helvetica'
                  FontSize: 10
                 FontUnits: 'points'
                FontWeight: 'normal'
             GridLineStyle: ':'
                     Layer: 'top'
            LineStyleOrder: '-'
                 LineWidth: 0.5
        MinorGridLineStyle: ':'
                  NextPlot: 'replace'
             OuterPosition: [1x4 double]
        PlotBoxAspectRatio: [1 1 1]
    PlotBoxAspectRatioMode: 'auto'
                Projection: 'orthographic'
                  Position: [1x4 double]
                TickLength: [0.01 0.025]
                   TickDir: 'in'
               TickDirMode: 'manual'
                TightInset: [1x4 double]
                     Title: 286.00244140625
                     Units: 'normalized'
                      View: [0 90]
                    XColor: [0 0 0]
                      XDir: 'normal'
                     XGrid: 'off'
                    XLabel: 287.00244140625
             XAxisLocation: 'bottom'
                      XLim: [-1 2]
                  XLimMode: 'manual'
                XMinorGrid: 'off'
                XMinorTick: 'off'
                    XScale: 'linear'
                     XTick: [1x0 double]
                XTickLabel: [11x3 char]
            XTickLabelMode: 'auto'
                 XTickMode: 'manual'
                    YColor: [0 0 0]
                      YDir: 'normal'
                     YGrid: 'off'
                    YLabel: 288.00244140625
             YAxisLocation: 'right'
                      YLim: [1 65]
                  YLimMode: 'manual'
                YMinorGrid: 'off'
                YMinorTick: 'off'
                    YScale: 'linear'
                     YTick: [10 20 30 40 50 60]
                YTickLabel: [6x2 char]
            YTickLabelMode: 'auto'
                 YTickMode: 'auto'
                    ZColor: [0 0 0]
                      ZDir: 'normal'
                     ZGrid: 'off'
                    ZLabel: 289.00244140625
                      ZLim: [0 1]
                  ZLimMode: 'auto'
                ZMinorGrid: 'off'
                ZMinorTick: 'off'
                    ZScale: 'linear'
                     ZTick: [0 0.5 1]
                ZTickLabel: ''
            ZTickLabelMode: 'auto'
                 ZTickMode: 'auto'
              BeingDeleted: 'off'
             ButtonDownFcn: @resetCurrentAxes
                  Clipping: 'on'
                 CreateFcn: []
                 DeleteFcn: []
                BusyAction: 'queue'
          HandleVisibility: 'on'
                   HitTest: 'on'
             Interruptible: 'off'
                  Selected: 'off'
        SelectionHighlight: 'on'
                       Tag: 'Colorbar'
                      Type: 'axes'
             UIContextMenu: 260.00244140625
                  UserData: []
                  Children: 259.00244140625
                    Parent: 1
                   Visible: 'on'
                  Location: 'EastOutside'

--
  "They called it golf because all the other four letter words
  were taken." -- Walter Hagen

Subject: colorbar title

From: Steven Lord

Date: 30 Jun, 2008 20:15:08

Message: 5 of 13


"Christopher Hummersone" <wheely_chairs@hotmail.com> wrote in message
news:g4b90m$4pv$1@fred.mathworks.com...
> Thanks for your reply Walter. However, I'm a little
> confused. Having not used handles much (just adding
> gca/gcf etc when required) I'm at a bit of a loss on how to
> do this. If I enter:
>
> cbar_axes = colorbar('peer',gca,...etc.);
> get(cbar_axes)
>
> I get an "invalid handle object" error message. Now I
> appreciate that I'm probably doing something stupid, so
> could you please point me in the right direction!?

Are you closing the figure containing the colorbar or removing the colorbar
before your call to GET? If so, the colorbar handle cbar_axes is no longer
a valid handle, which would give the error you mentioned.

If that's not the case, can you describe in more depth exactly what you're
doing when you receive this error, and give the full text of the error
message as well as the version you're using?

--
Steve Lord
slord@mathworks.com

Subject: colorbar title

From: Christopher Hummersone

Date: 30 Jun, 2008 21:26:01

Message: 6 of 13

Hi both,

Well it seems to be working now although I swear I haven't
changed anything! I'm on R2007A. But now I find that I'm
unable to set() the 'ylabel' property and I get the error
"Value must be a handle". In the property list I notice
that both 'ylabel' and 'title' have numeric values, which I
guess is to do with Matlab storing handles as floating point
numbers? Is this the problem? Can I convert a string to
handle (if this is even the step to take)?

Thanks a lot for your help,

Chris
--------
code:

figure; plot(rand(5,99));
t = colorbar('peer',gca); get(t,'ylabel');
set(t,'ylabel','My Title');

Subject: colorbar title

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 Jun, 2008 21:27:46

Message: 7 of 13

In article <g4bj19$24p$1@fred.mathworks.com>,
Christopher Hummersone <wheely_chairs@hotmail.com> wrote:

>figure; plot(rand(5,99));
>t = colorbar('peer',gca); get(t,'ylabel');
>set(t,'ylabel','My Title');

figure; plot(rand(5,99));
t = colorbar('peer',gca);
set(get(t,'ylabel'),'String', 'My Title');

--
  "The human mind is so strangely capricious, that, when freed from
  the pressure of real misery, it becomes open and sensitive to the
  ideal apprehension of ideal calamities." -- Sir Walter Scott

Subject: colorbar title

From: Christopher Hummersone

Date: 30 Jun, 2008 21:50:20

Message: 8 of 13

Fantastic! Worked perfectly! Thank you so much :-)

If anyone else is interested my code is:

set(get(cbar_handle,'ylabel'),'string','My
Title','fontsize',16,etc...)

Chris

Subject: colorbar title

From: Steven Lord

Date: 1 Jul, 2008 13:56:41

Message: 9 of 13


"Christopher Hummersone" <wheely_chairs@hotmail.com> wrote in message
news:g4bj19$24p$1@fred.mathworks.com...
> Hi both,
>
> Well it seems to be working now although I swear I haven't
> changed anything! I'm on R2007A. But now I find that I'm
> unable to set() the 'ylabel' property and I get the error
> "Value must be a handle".

I know Walter gave you the answer, but I'd like to explain this for future
reference. The YLabel property of an axes stores a handle to a text object;
that's why you received an error when you tried to set the YLabel property
of the colorbar axes to a string.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#XLabel

> In the property list I notice
> that both 'ylabel' and 'title' have numeric values, which I
> guess is to do with Matlab storing handles as floating point
> numbers?

Correct.

> Is this the problem? Can I convert a string to
> handle (if this is even the step to take)?

As Walter showed you, GET the axes YLabel property (which gives you a handle
to the text object) and SET that handle's String property to the desired
label.

Alternately, the YLABEL function accepts an axes handle as input and sets
the y-axis label for that axes to the string you passed into YLABEL.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ylabel.html

plot(1:10);
h = colorbar;
ylabel(h, 'My Colorbar');

--
Steve Lord
slord@mathworks.com

Subject: colorbar title

From: Christopher Hummersone

Date: 4 Jul, 2008 12:51:01

Message: 10 of 13

Thanks so much for taking the time to explain that Steve,
you've really cleared it up for me :-)

Chris

Subject: colorbar title

From: Nick Sinclair

Date: 8 Jul, 2010 22:07:04

Message: 11 of 13

If you have already made a colorbar and want to find the handle to the colorbar axis so that you can set the properties. This works:

ax = findobj(get(FIGUREHANDLE,'Children'),'Tag','Colorbar');

or

ax = findobj(get(gcf,'Children'),'Tag','Colorbar'); %if it's the current figure

Subject: colorbar title

From: Jim

Date: 11 Nov, 2010 16:17:04

Message: 12 of 13

"Christopher Hummersone" <wheely_chairs@hotmail.com> wrote in message <g4b0eu$qbm$1@fred.mathworks.com>...
> Hi all,
>
> Does anyone know how to add a title to a colorbar? It
> should be something like 'xlabel' except the text would be
> to the right of the bar; alas no such property seems to
> exist for the colorbar.
>
> Thanks,
>
> Chris

Simplest is:
   hd= colorbar;
   set(get(hd,'title'),'String','TITLE');
Jim

Subject: colorbar title

From: Stine Gro Jensen

Date: 22 Nov, 2010 12:24:04

Message: 13 of 13

"Jim " <jleuer@gmail.com> wrote in message <ibh4u0$5bb$1@fred.mathworks.com>...
> "Christopher Hummersone" <wheely_chairs@hotmail.com> wrote in message <g4b0eu$qbm$1@fred.mathworks.com>...
> > Hi all,
> >
> > Does anyone know how to add a title to a colorbar? It
> > should be something like 'xlabel' except the text would be
> > to the right of the bar; alas no such property seems to
> > exist for the colorbar.
> >
> > Thanks,
> >
> > Chris
>
> Simplest is:
> hd= colorbar;
> set(get(hd,'title'),'String','TITLE');
> Jim

Hi all,

You CAN use the xlabel, ylabel and title functions in the traditional way. Just write:

ylabel(colorbar,'My colorbar') - text will be placed on the right of the colorbar
xlabel(colorbar,'My colorbar') - text will be placed below colorbar
title(colorbar,'My colorbar') - text will be placed above colorbar

Cheers,
Stine

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
find Nick Sinclair 8 Jul, 2010 18:09:22
colorbar Nick Sinclair 8 Jul, 2010 18:09:22
findobj Nick Sinclair 8 Jul, 2010 18:09:22
handle Nick Sinclair 8 Jul, 2010 18:09:22
colorbar title Christopher Hummersone 30 Jun, 2008 12:10:24
rssFeed for this Thread

Contact us at files@mathworks.com