Clear Filters
Clear Filters

Log plots - unwanted tick marks

23 views (last 30 days)
Richard Newton
Richard Newton on 16 Jul 2017
Answered: Joseph Olson on 22 May 2020
I want to create a plotyy with the left tick marks at intervals of 100 from 1000 to 100 and then up to 70, and then on the right tick marks at arbitrary intervals (the working example is in hundreds from 980 to 80). My problem is that there are small tick marks at 80 and 90 on the left axis, and more importantly ticks at intervals of 100 on the right axis, which must be removed to make my plot readable.
I've turned 'Box', 'YMinorTick' and 'YMinorGrid' off, and this hasn't solved it. It looks like the little ticks for a tenth of the distance between 10^x and 10^(x+1) (e.g. every 100 between 100 and 1000; every 10 between 10 and 100) are there automatically on the grid. To what property do these little ticks belong to, and how do you remove them?
figure(2); clf
[ax,pl(1),pl(2)] = plotyy([0 30],[1 1000],[0 30],[1 1000]);
set([pl(1) pl(2)],'LineStyle','None')
set([ax(1) ax(2)],'YDir','reverse','YScale','log','YLim',[70 1000])
set([ax(1) ax(2)],'Box','Off')
set(ax(1),'YTick',[70 100:100:1000])
set(ax(2),'YTick',[80:100:1080])
set([ax(1) ax(2)],'YMinorTick','Off')
set([ax(1),ax(2)],'YMinorGrid','Off')
set(2, 'Units', 'inches'); set(2, 'Position', [2 1 4 4]); set(2,'renderer','painters');
set(2, 'Visible','On'); set(2, 'PaperUnits', 'inches'); set(2, 'PaperPosition', [2 1 4 4]);
saveas(2,'problem.eps','epsc')
The result is this figure.
  2 Comments
Walter Roberson
Walter Roberson on 16 Jul 2017
Which MATLAB release and which operating system are you using?
I do not get the extra ticks for R2017a on OS-X El Capitan
Richard Newton
Richard Newton on 16 Jul 2017
I'm on R2015b on Windows 10.

Sign in to comment.

Answers (3)

Joseph Olson
Joseph Olson on 22 May 2020
For me, using 2019b, I can get rid of them using
set(gca,'YMinorTick','off')

dpb
dpb on 16 Jul 2017
Edited: dpb on 16 Jul 2017
The ticks belong to the opposite-hand axes; their visibility can only be controlled by the outer box property being 'on|off'
You can easily illustrate the problem simply with less confusion by just one axes with
figure
axes; % no RH vertical axis is drawn
box on % now the RH axis shows up and has the LH ticks builtin
With your code you should not see the "extra" ticks; which release are you using? Here (R2014b) with
figure
[ax,pl(1),pl(2)] = plotyy([0 30],[1 1000],[0 30],[1 1000]);
set([pl(1) pl(2)],'LineStyle','None')
set([ax(1) ax(2)],'YDir','reverse','YScale','log','YLim',[70 1000])
set([ax(1) ax(2)],'Box','Off')
set(ax(1),'YTick',[70 100:100:1000])
set(ax(2),'ytick',[80:100:1080])
the result is
Unfortunately, then you have the ugly opening at the top that you have to fill manually. It appears your figure is perhaps not reflective of identically the code shown; there are ticks at 80 and 90 on LH axes as well.
However, after
set(ax,'box','on')
one gets what your figure shows,
It's always been unfortunate that HG treats the axes as the full box rather than the two sides independently; plotyy creates two totally independent axes laying on top of each other and so they fight each other when things don't align precisely. The only way I know of to use box 'on' and not have the effect show up is to ensure that there are precisely the same number of ticks on each axes at the same spacing--this is at least reasonably easy to do with linear axes although even and pretty numbering may be tough--but is virtually impossible for log scales since they don't scale linearly excepting over full decades.
You could try the new yyaxis instead of plotyy and subsequent ruler object and see if there's any better control although I'm sure the underlying axes are the same either way. Well, that doesn't help, rats! :( There is no additional granularity on the ruler object; a couple/three new properties that are useful, but still color and all are just a single property for each axes as a whole, not specifiable as RH/LH sides of the same axes.
I have shown how to do some specialized plots to add more axes onto the L/R sides of the figure; that same trick could be used here except instead of moving them over to the left and right and decreasing the width of the main axes to create room, overlay them directly onto the existing. The "trick" was/is to use a very tiny width value in the 'position' vector so that there is no visible extent along the x-axis direction. In this manner you could set the ticks on the existing axes to the null vector making them disappear and use the two additional with no x-extent for the actual ticks. Then there would be no conflicting tick marks on the opposite axes visible and you could also then use 'box', 'on' on the present axes to close in the top.
Here's link to that thread <4 y-axes>
There's no real excuse for having to go through such gyrations, but it's just "how HG works", unfortunately. :(
  1 Comment
Richard Newton
Richard Newton on 16 Jul 2017
Edited: Richard Newton on 16 Jul 2017
I'm using MATLAB 2015b - so I don't have yyaxis. There's a subtle difference between what my figure shows and what your figure shows: the little ticks you have are blue - therefore belong to ax(1), mine are orange - therefore belong to ax(2), and also there are little blue ticks on the left axis for 80 and 90. Therefore the box is not the issue - both ax(1) and ax(2) boxes are off anyway.
Walter Robertson's comment suggests the problem doesn't arise on later versions, and your answer suggests it doesn't arise on earlier versions, so I'll try it on the other version I have: 2013a.
EDIT: I can confirm this doesn't happen on 2013a. I guess it's just another quirk of 2015b.

Sign in to comment.


Walter Roberson
Walter Roberson on 16 Jul 2017
"YTick labels for PLOTYY with semilog axes are incorrect in versions later than R2008a."
Fixed in R2016a.
However, the workaround given there, of setting YScale to 'log' after doing the log plot, does not appear to work with your code.
  1 Comment
Richard Newton
Richard Newton on 16 Jul 2017
Edited: Richard Newton on 16 Jul 2017
Ah... it's nice to know others have encountered the problem previously and it's a known bug. My workaround was to use version 2013a, which thankfully I have on another computer. Thanks for the help everyone!
For what it's worth, here's the actual plot (with the actual data removed): trying to work out which ticks are vertical levels, and which ones shouldn't be there is hard.
2015b: the bad plot
2013a: the good plot

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!