Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Control display and position of axis exponent label to prevent title overlap

551 views
Skip to first unread message

AJP

unread,
Sep 29, 2010, 12:51:19 PM9/29/10
to
In any ordinary 2D x-y plot, MATLAB will automatically add "x10^n" exponent labels to the axis if the plotted data is large enough in magnitude.

For example, type the following at the command line:

x=[1,2,3];y=[1e6,2e6,3e6];figure;plot(x,y);

As you can see, a "x10^6" exponent label has been automatically added at the top of the y-axis.

Unfortunately, if a plot or subplot is narrow or the title is long, or both, then the default position of the exponent label can annoyingly overlap the title.

Is there any way to control the exponent label? I would greatly appreciate any help with the following questions:

1) Can the default position and/or orientation of the exponent label be changed so that it doesn't overlap plot titles?

2) If (1) is not possible, or very awkward, can the exponent simply be turned off? If so, I can then probably calculate an equivalent exponent and insert it as a string into the axis label.

P.S. I anticipate that some may suggest that instead of going to the trouble of moving or turning off the exponent label, I should move the title to accommodate it. However, I can already do this so may I kindly request suggestions for exponent label control only please!

Thanks to anyone who can help!

Walter Roberson

unread,
Sep 29, 2010, 1:18:06 PM9/29/10
to
On 10-09-29 11:51 AM, AJP wrote:
> In any ordinary 2D x-y plot, MATLAB will automatically add "x10^n"
> exponent labels to the axis if the plotted data is large enough in
> magnitude.

> Is there any way to control the exponent label?

No, other than turning it off.

> I would greatly
> appreciate any help with the following questions:
>
> 1) Can the default position and/or orientation of the exponent label be
> changed so that it doesn't overlap plot titles?

No.

> 2) If (1) is not possible, or very awkward, can the exponent simply be
> turned off? If so, I can then probably calculate an equivalent exponent
> and insert it as a string into the axis label.

Yes. If the [xy]ticklabelmode is 'manual' then the exponent is not added to
that axes. [xy]ticklabelmode is automatically set to 'manual' if you set
[xy]ticklabel yourself.

AJP

unread,
Sep 29, 2010, 1:40:21 PM9/29/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <i7vshm$ng3$1...@canopus.cc.umanitoba.ca>...
=================================


Is the syntax for this: set(gca,'XTickLabelMode','manual')

Because it doesn't seem to have worked. The exponent is still there, unfortunately.

Walter Roberson

unread,
Sep 29, 2010, 1:55:15 PM9/29/10
to

If you want to do it by setting the label mode, then
You have to set XTickLabelMode or YTickLabelMode before you produce the graph,
and you have to have "hold on" in effect or else the automatic cla() that is
done will reset the mode. Labels will still be produced automatically but they
many take on unexpected values.

You are better off setting the XTickLabel or YTickLabel variables manually.
For example,


h = plot(1:10,exp(1:10));
set(gca,'YTick',2.^(10:16),'YTickLabel',num2str(2.^(10:16).'))

AJP

unread,
Oct 1, 2010, 2:10:20 PM10/1/10
to
Walter Roberson <robe...@hushmail.com> wrote in message <i7vunb$rtp$1...@canopus.cc.umanitoba.ca>...
===============================================

Thanks for the suggestions.

I'll have to work out how to do your suggestion for data that is unknown before the plotting, so I'll have to define the ticks and labels carefully, but I should be able to work it out.

Walter Roberson

unread,
Oct 1, 2010, 2:36:23 PM10/1/10
to
On 10-10-01 01:10 PM, AJP wrote:
> Walter Roberson <robe...@hushmail.com> wrote in message

>> h = plot(1:10,exp(1:10));


>> set(gca,'YTick',2.^(10:16),'YTickLabel',num2str(2.^(10:16).'))

> I'll have to work out how to do your suggestion for data that is unknown


> before the plotting, so I'll have to define the ticks and labels
> carefully, but I should be able to work it out.

h = plot(1:10,exp(1:10));
set(gca,'YTickLabel',num2str(get(gca,'YTick').'))

Alex Barker

unread,
Jan 8, 2013, 12:35:16 AM1/8/13
to

>
> Unfortunately, if a plot or subplot is narrow or the title is long, or both, then the default position of the exponent label can annoyingly overlap the title.
>
> Is there any way to control the exponent label? I would greatly appreciate any help with the following questions:
>


I had the same problem, and have a cheeky solution that works for me:

I add a blank row below my title text, so that it clears the exponent. eg:

title({'My big long title'; [] })

...Just in case anyone else ends up here from google like I did.

Alex

unread,
Nov 3, 2013, 11:04:13 AM11/3/13
to
"Alex Barker" <blahbl...@blah.blah> wrote in message <kcgb6k$h62$1...@newscl01ah.mathworks.com>...

> I had the same problem, and have a cheeky solution that works for me:
>
> I add a blank row below my title text, so that it clears the exponent. eg:
>
> title({'My big long title'; [] })
>
> ...Just in case anyone else ends up here from google like I did.

I really like this idea. It's a clever way to improve formatting, not just for a title but for anything similar. Well done on coming up with this - I shall use it in the future I suspect.
0 new messages