How can I remove left y-axis tick marks from the right y-axis, AND retain the top x-axis with MatLab 2015a?
조회 수: 19 (최근 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!