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

Removing Tick Marks in Plot

571 views
Skip to first unread message

Brent Selby

unread,
Oct 10, 2008, 4:40:18 PM10/10/08
to
I am plotting several functions using the plot and plotyy functions. When I use plotyy to add a second y-axis the tick marks from the first (left) y-axis remain on the right side. This makes the graph look bad and confusing. Is there anyway to remove these unwanted tick marks?

someone

unread,
Oct 10, 2008, 5:06:02 PM10/10/08
to
"Brent Selby" <fgw...@gmail.com> wrote in message <gcoeji$cu0$1...@fred.mathworks.com>...

> I am plotting several functions using the plot and plotyy functions. When I use plotyy to add a second y-axis the tick marks from the first (left) y-axis remain on the right side. This makes the graph look bad and confusing. Is there anyway to remove these unwanted tick marks?

% Use the form:

[AX,H1,H2] = plotyy(...)

% AX is a handle to both axes
% AX(1) is "first" plot and
% AX(2) is "second" plot

set(AX,'YTick,[]) % empty vector

% will remove BOTH y-axis tick marks

Walter Roberson

unread,
Oct 10, 2008, 5:08:11 PM10/10/08
to

Which version are you using? I don't observe that in 2007a. Are you sure you don't have 'hold on'
keeping a previous axes in place? If you are using plot() and hold on and plotyy, you probably
shouldn't be doing that; instead, check out the Matlab File Exchange (FEX) contribution 'plt'.

e.g.,
plotyy(1:20,rand(1,20),1:100,50*log(rand(1,100)))

Brent Selby

unread,
Oct 10, 2008, 5:54:01 PM10/10/08
to
version 7.1.0248 (R14) SP3 from 2005
it seems that plotyy creates two separate graphs that happen to be in the same window - given the referencing scheme and response to setting the axes and other things they are independent.

Ex: If I move the legend for the left axis outside the plot area will adjust for those functions plotted against the left axis - there are 2 borders and the x values at the bottom are printed twice over top of one another because some functions' plot area is 75% screen width and others are 60%.

The point is that plotting on 2 axes is annoying because matlab doesn't seem to recognize both at once so they do their own thing, and that means putting tick marks on both sides for axis 1.

Walter Roberson

unread,
Oct 11, 2008, 6:15:10 PM10/11/08
to
Brent Selby wrote:
> version 7.1.0248 (R14) SP3 from 2005
> it seems that plotyy creates two separate graphs that happen to be in the same window -
> given the referencing scheme and response to setting the axes and other things they are independent.

Yes, it creates two axes in the same position and manipulates the axes properties for the
two graphs.



> Ex: If I move the legend for the left axis outside the plot area will adjust for those
> functions plotted against the left axis - there are 2 borders and the x values at the bottom
> are printed twice over top of one another because some functions' plot area is 75% screen
> width and others are 60%.

> The point is that plotting on 2 axes is annoying because matlab doesn't seem to recognize both
> at once so they do their own thing, and that means putting tick marks on both sides for axis 1.

In versions later than the one you have, coordination between axes is handled more smoothly
by using linkaxes() and (later) linkprop().

I would suggest that you explore the Matlab File Exchange (FEX) contribution 'plt' if
it will run in your Matlab version.

Paul Mennen

unread,
Oct 12, 2008, 2:11:09 AM10/12/08
to
Walter Roberson wrote
>> The point is that plotting on 2 axes is annoying because
>> matlab doesn't seem to recognize both at once so they
>> do their own thing, and that means putting tick marks
>> on both sides for axis 1.
> In versions later than the one you have, coordination
> between axes is handled more smoothly
> by using linkaxes() and (later) linkprop().
> I would suggest that you explore the Matlab (FEX)

> contribution 'plt' if it will run in your Matlab version.

Thanks Walter for suggesting 'plt' as a solution.
And of course I agree that it handles a plot with both
left and right y axes with more ease and flexibility.
(The more important benefits however show up when you
need to plot more than two traces).

Your question about the Matlab version shouldn't be a
factor as it will run in all versions from the latest
all the way back to ver 6.1 (R12.1) which was released
over seven years ago.

And by the way, there is an updated version of plt that
I put up on the FEX a few days ago (my 33rd update since
the first release in 2004).

And for the example you gave:

> plotyy(1:20,rand(1,20),1:100,50*log(rand(1,100)))

To do that with plt, you have to specify which trace
you want to put on the right axis with the 'right'
parameter, as in:

plt(1:20,rand(1,20),1:100,50*log(rand(1,100)),'right',2)

Be sure to ask me if you have any questions or problems
when using plt.

~Paul
paul (at) mennen (dot) org

Brent Selby

unread,
Oct 13, 2008, 9:38:01 AM10/13/08
to
Paul, Walter, thank you both for your help. I will attempt in implement this using plt.

Joe Tyburczy

unread,
Oct 1, 2009, 12:14:04 PM10/1/09
to
FYI, I ran into the same problem using plotyy -- and I think I've figured out how the default setting avoids this. When using plotyy without manual axis modification, it actually plots the right axis directly on top of the ticks from the left axis. In order to avoid the ticks from the left axis showing on the right, you have to set ticks on the right axis so that they occur exactly covering the ones from the left axis. If you set the Ylim and Ytick of the right axis so that they line up exactly with the left hand axis, they will cover them.

For example:
[ax, h1, h2] = plotyy(x1, y1, x2, y2);
set(ax(1), 'Ylim', [0 10], 'YTick', [0:2:10]); % sets ticks for right axis at 0,2,4,6,8,10
set(ax(2), 'Ylim', [0 1], 'YTick', [0:0.1:1]); % sets left axis ticks at 0, 0.1, 0.2 etc.

In this example, every other tick mark on the right axis will occur right on top of the ones from the left axis and cover it.


"Brent Selby" <fgw...@gmail.com> wrote in message <gcvivp$pkf$1...@fred.mathworks.com>...

Michael Tan

unread,
Oct 14, 2009, 5:35:03 PM10/14/09
to
Hi Joe, I found a solution where you do not have to map the right y-axis to cover the left y-axis tick. Here what you can do.

set(gca,'box','off'); %remove the box
set(ax(2), XAxisLocation','top','linewidth',3) %cover the top box manually
set(ax(2),'XTick',[]) %remove the ticks

Michael

"Joe Tyburczy" <color...@gmail.com> wrote in message <ha2kgc$nus$1...@fred.mathworks.com>...

Tuan Phan

unread,
Oct 28, 2010, 9:16:04 PM10/28/10
to
"Brent Selby" <fgw...@gmail.com> wrote in message <gcoeji$cu0$1...@fred.mathworks.com>...

> I am plotting several functions using the plot and plotyy functions. When I use plotyy to add a second y-axis the tick marks from the first (left) y-axis remain on the right side. This makes the graph look bad and confusing. Is there anyway to remove these unwanted tick marks?

I have found a way to fix that as I got the same need like you. It is amazingly simple:

given some x, y1, y2
>>[ax,h1,h2]=plot(x,y1,x,y2);
>>set(ax(2),'Box','Off'); %remove y1 ticks from the right side
>> set(ax(1),'Box','Off'); @remove y2 ticks from the left side

regards
Tuan A. Phan

Sven Schoeberichts

unread,
Dec 20, 2011, 8:41:09 AM12/20/11
to
"Tuan Phan" <phantu...@yahoo.com> wrote in message <iad78k$g3q$1...@fred.mathworks.com>...
That is exactly what I needed, thank you very much!

Daniel

unread,
Mar 2, 2015, 7:38:39 AM3/2/15
to
Hi Brent,

I hit this issue as well when I changed the Ylim of the right plot. I got around it by changing the left plot Ylim in the same proportions (to realign the tick marks on the right and hide the left plot's behind the right plot's):

[hAx,hLine1,hLine2] = plotyy(X,Y1,X,Y2);
set(hAx(2),'ylim',[0 1.2]);
set(hAx(1),'ylim',get(hAx(1),'ylim').*[0 1.2]);

Cheers,
Daniel

"Brent Selby" <fgw...@gmail.com> wrote in message <gcoeji$cu0$1...@fred.mathworks.com>...
0 new messages