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:
Control display and position of axis exponent label to prevent title overlap

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

From: AJP

Date: 29 Sep, 2010 16:51:19

Message: 1 of 8

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!

Subject: Control display and position of axis exponent label to prevent

From: Walter Roberson

Date: 29 Sep, 2010 17:18:06

Message: 2 of 8

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.

Subject: Control display and position of axis exponent label to prevent

From: AJP

Date: 29 Sep, 2010 17:40:21

Message: 3 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <i7vshm$ng3$1@canopus.cc.umanitoba.ca>...
> On 10-09-29 11:51 AM, AJP wrote:
>
> 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.
=================================


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

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

Subject: Control display and position of axis exponent label to prevent

From: Walter Roberson

Date: 29 Sep, 2010 17:55:15

Message: 4 of 8

On 10-09-29 12:40 PM, AJP wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <i7vshm$ng3$1@canopus.cc.umanitoba.ca>...
>> On 10-09-29 11:51 AM, AJP wrote:
>>
>> 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.
> =================================
>
>
> Is the syntax for this: set(gca,'XTickLabelMode','manual')
>
> Because it doesn't seem to have worked. The exponent is still there,
> unfortunately.

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).'))

Subject: Control display and position of axis exponent label to prevent

From: AJP

Date: 1 Oct, 2010 18:10:20

Message: 5 of 8

Walter Roberson <roberson@hushmail.com> wrote in message <i7vunb$rtp$1@canopus.cc.umanitoba.ca>...
> On 10-09-29 12:40 PM, AJP wrote:
> > Walter Roberson <roberson@hushmail.com> wrote in message
> > <i7vshm$ng3$1@canopus.cc.umanitoba.ca>...
> >> On 10-09-29 11:51 AM, AJP wrote:
> >>
> >> 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.
> > =================================
> >
> >
> > Is the syntax for this: set(gca,'XTickLabelMode','manual')
> >
> > Because it doesn't seem to have worked. The exponent is still there,
> > unfortunately.
>
> 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).'))
===============================================

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.

Subject: Control display and position of axis exponent label to prevent

From: Walter Roberson

Date: 1 Oct, 2010 18:36:23

Message: 6 of 8

On 10-10-01 01:10 PM, AJP wrote:
> Walter Roberson <roberson@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').'))

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

From: Alex Barker

Date: 8 Jan, 2013 05:35:16

Message: 7 of 8


>
> 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.

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

From: Alex

Date: 3 Nov, 2013 16:04:13

Message: 8 of 8

"Alex Barker" <blahblahblah@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.

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