Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
axis label text disappears with linked axes

Subject: axis label text disappears with linked axes

From: HJ

Date: 20 Jan, 2014 20:40:11

Message: 1 of 5

When I run the following code...

figure;
ax_left=axes; grid on;
ax_right=axes('position',get(ax_left,'position'),'yaxislocation','right','color','none'); grid on;
ylabel(ax_left,'left ylabel');
ylabel(ax_right,'right ylabel');
linkaxes([ax_left ax_right],'xy');
x=1:10; y=x.^1.5;
plot(ax_left,x,y,'b.');

... the "left ylabel" text disappears. I can put it back with

set(get(ax_left,'ylabel'),'string','left ylabel')

but why does it disappear in the first place?

Note: I'm forced to run R2006b at the moment. Is this by chance a known bug that has been fixed in any newer release?

-H

Subject: axis label text disappears with linked axes

From: Steven Lord

Date: 20 Jan, 2014 21:48:08

Message: 2 of 5


"HJ" <hjfarkmail.notthispart@notthisparteither.lycos.com> wrote in message
news:lbk1jb$5bd$1@newscl01ah.mathworks.com...
> When I run the following code...
>
> figure;
> ax_left=axes; grid on;
> ax_right=axes('position',get(ax_left,'position'),'yaxislocation','right','color','none');
> grid on;
> ylabel(ax_left,'left ylabel');
> ylabel(ax_right,'right ylabel');
> linkaxes([ax_left ax_right],'xy');
> x=1:10; y=x.^1.5;
> plot(ax_left,x,y,'b.');
>
> ... the "left ylabel" text disappears. I can put it back with
>
> set(get(ax_left,'ylabel'),'string','left ylabel')
>
> but why does it disappear in the first place?

Because by default PLOT resets the properties of the axes, including the
YLABEL. See the "Adding Plots to an Existing Graph" section of this
documentation page:

http://www.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html

as well as the "Preparing Figures and Axes for Graphics" section on this
documentation page for more information:

http://www.mathworks.com/help/matlab/creating_plots/controlling-graphics-output.html

> Note: I'm forced to run R2006b at the moment. Is this by chance a known
> bug that has been fixed in any newer release?

Not A Bug. Expected behavior. See:

ax = axes;
plot(1:10, 1:10);
ylabel(ax, 'This label will disappear after the PAUSE');
pause
plot(1:10, 10:-1:1)

Compare:

clf
ax2 = axes;
plot(1:10, 1:10);
ylabel(ax2, 'This label will NOT disappear after the PAUSE');
pause
set(ax2, 'NextPlot', 'replacechildren')
plot(1:10, 10:-1:1)

Now try using HOLD ON instead of setting the axes NextPlot property in that
second example. Three different behaviors, all correct, all intended for
different purposes.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: axis label text disappears with linked axes

From: Kevin Ellis

Date: 20 Jan, 2014 21:49:07

Message: 3 of 5

"HJ" <hjfarkmail.notthispart@notthisparteither.lycos.com> wrote in message <lbk1jb$5bd$1@newscl01ah.mathworks.com>...
> When I run the following code...
>
> figure;
> ax_left=axes; grid on;
> ax_right=axes('position',get(ax_left,'position'),'yaxislocation','right','color','none'); grid on;
> ylabel(ax_left,'left ylabel');
> ylabel(ax_right,'right ylabel');
> linkaxes([ax_left ax_right],'xy');
> x=1:10; y=x.^1.5;
> plot(ax_left,x,y,'b.');
>
> ... the "left ylabel" text disappears. I can put it back with
>
> set(get(ax_left,'ylabel'),'string','left ylabel')
>
> but why does it disappear in the first place?
>
> Note: I'm forced to run R2006b at the moment. Is this by chance a known bug that has been fixed in any newer release?
>
> -H

HJ,

I have had a similar problem in the past. I always believe the order of your lines of code is critically important when plotting. For example, your code works great and if you change the order around to:

figure;
ax_left=axes; grid on;
ax_right=axes('position',get(ax_left,'position'),'yaxislocation','right','color','none'); grid on;
x=1:10; y=x.^1.5;
plot(ax_left,x,y,'b.');
ylabel(ax_left,'left ylabel');
ylabel(ax_right,'right ylabel');
linkaxes([ax_left ax_right],'xy');

No labels disappear and it looks like the result you were looking for. I believe if you label the graph and then plot, the labels get overwritten. When I need to make a graph I always think plot the data first and then make the graph look professional by adding labels, coloring lines, adding a grid, etc.

Anyways, hope this helps.

Kevin

Subject: axis label text disappears with linked axes

From: HJ

Date: 24 Jan, 2014 01:12:09

Message: 4 of 5

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lbk5io$bk$1@newscl01ah.mathworks.com>...
> Because by default PLOT resets the properties of the axes, including the
> YLABEL. See the "Adding Plots to an Existing Graph" section of this
> documentation page:
[...]

Steve-

This is hugely helpful. I'd overlooked this subtle (to me, anyway) detail previously. Thanks!

-H

Subject: axis label text disappears with linked axes

From: HJ

Date: 24 Jan, 2014 01:19:08

Message: 5 of 5

"Kevin Ellis" wrote in message <lbk5kj$11d$1@newscl01ah.mathworks.com>...
> I have had a similar problem in the past. I always believe the order of your lines of code is critically important when plotting. For example, your code works great and if you change the order around to:
[...]

Kevin--

Thanks for the explanation. My code snipped is a simplified/distilled version of my actual code (which involves multiple PLOTYY subplots, etc.) and I'd labeled the axes _after_ plotting, as you suggest. But I also had a callback set up to re-render certain ticklabels in response to zooming (via listener/callback), and I think that's what was causing the text to disappear. Anyway, thanks to your and Steve's suggestions, I have it working correctly now.

Cheers,

-H

Tags for this Thread

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.

Contact us