How can I remove left y-axis tick marks from the right y-axis, AND retain the top x-axis with MatLab 2015a?
28 次查看(过去 30 天)
显示 更早的评论
Hello. I am needing to plot a three line graph with two y-axis. One line will be tied to the left y-axis, and two lines will be tied to the right y-axis. The two lines plotted against the right y-axis need to be black (one solid the other dashed). The tick range and the limits on the left y-axis will be (MatLab) auto generated based on the values being plotted. The tick range on the right y-axis will be 0.0 to 1.0 with a tick at every 0.1 unit, and it's limits -0.1 to 1.1. The problem stems from plotyy adding left y-axis tick marks to the right y-axis, which I not what I want. So how can I remove left y-axis tick marks from the right y-axis, AND retain the top x-axis? Below is a segment from my script attempting to plot what I just described.
I have been unsuccessful finding a solution in MatLab Central that will work on 2015a.
Regards, Ed
[ax,~,H2] = plotyy(x,y1,x,[y2, y3],'plot'); % plot the graph (y1 = left y-axis, y2 & y3 = right y-axis)
set(H2(1),'LineStyle','-','Color','black'); % set y2 plot to be a solid black line
set(H2(2),'LineStyle','--','Color','black'); % set y3 plot to be a dash black line
set(ax(2),'YLim',[(-0.1) 1.1]); % set plotting limits for right y-axis
set(ax(2),'YTick',0.0:0.1:1.0); % set the tick properties for right y-axis
set(ax,'YColor','black); % make both y-axis black
set(ax(1),'Box','Off'); % remove left y-axis tick marks from the right y-axis ... BUT THIS ALSO REMOVES THE TOP X-AXIS, WHICH IS NOT WHAT I WANT TO DO
% the following are commands I tried without success. Note: I tried these commands separately per execution.
set(ax,'XAxisLocation','top','XTicklabel',[]); % one attempt
set(ax(1),'XAxisLocation','top','XTicklabel',[]); % another attempt
set(ax(2),'XTicklabel','','XAxisLocation','top'); % another attempt
0 个评论
回答(2 个)
dpb
2016-9-3
编辑:Thorsten
2016-9-5
x=[1:100].';y=randn(100,1); % some dummy data to plot to make axes w/ differing ranges
hAx=plotyy(x,y,x,sqrt(abs(y))/pi);
ylim(hAx(2),[0 1]) % set RH axes so are disparate from left
box(hAx(1),'off') % turn off LH axes ticks on RH frame
set(hAx(2),'xaxisloc','top','xticklab',[]) % RH x-axis to top, leave ticks but no labels
Isn't that the effect you're looking for?
2 个评论
dpb
2016-9-5
编辑:dpb
2016-9-5
No, I'm still at R2012b; not enough 'puter for later releases...
"set(hAx(2),'xaxisloc','top','xticklab',[])" command had no effect..."
But, show a complete example code like the above that has the symptom to be sure we're talking apples and apples...it's possible you've done something in a more complex sequence that has caused one axes object to have occluded the other but we can't reproduce your actual case here so need to prove it's an issue in the simple case first--if it's not there, the problem is elsewhere in your actual sequence of commands. Also, it never hurts to attach the image; sometimes it'll provide other klews...
Thorsten
2016-9-5
So what's wrong with
x=[1:100].';y=randn(100,1); % some dummy data to plot to make axes w/ differing ranges
hAx=plotyy(x,y,x,sqrt(abs(y))/pi);
ylim(hAx(2),[0 1])
13 个评论
dpb
2016-9-7
编辑:dpb
2016-9-8
Thorsten is on R2015b, not ...a. As noted, I'm still at R2012b.
It's possible there's a difference in HG2 between the two letter releases, but I'd be somewhat surprised.
The key to success is
hAx(2).XAxis.Visible = 'on';
What was the syntax error you received. If it's that there's no such property as 'XAxis' or somesuch, it would seem your only recourse would be to upgrade. If the NumericRuler object exists, then you should be able to set its 'visible' property; the overall axes 'visible' property is already set to 'on' so setting it again won't make it any "onner"; iow, that's a do-nothing operation and the lack of visibility of the axis ruler/ticks isn't owing to it. That's what Thorsten's experiments for us showed (since I can't test HG2 here)
ADDENDUM What about the single plot sample; can you see the tick marks there? If you can get that to work, it should, it seems, be possible to get it to work with plotyy as well.
另请参阅
类别
在 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!