Log plots - unwanted tick marks
32 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2017-7-16
Which MATLAB release and which operating system are you using?
I do not get the extra ticks for R2017a on OS-X El Capitan
回答(3 个)
Joseph Olson
2020-5-22
For me, using 2019b, I can get rid of them using
set(gca,'YMinorTick','off')
0 个评论
dpb
2017-7-16
编辑:dpb
2017-7-16
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.
There's no real excuse for having to go through such gyrations, but it's just "how HG works", unfortunately. :(
Walter Roberson
2017-7-16
"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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!