How can I remove left y-axis tick marks from the right y-axis, AND retain the top x-axis with MatLab 2015a?

25 vues (au cours des 30 derniers jours)
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

Réponses (2)

dpb
dpb le 3 Sep 2016
Modifié(e) : Thorsten le 5 Sep 2016
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 commentaires
Booker
Booker le 4 Sep 2016
hello dpb.
Unfortunately for me, the "set(hAx(2),'xaxisloc','top','xticklab',[])" command had no effect on my graphs. The top X-Axis did not reappear. Are you using r2015a?
Thank you for taking the time to answer this.
Book
dpb
dpb le 5 Sep 2016
Modifié(e) : dpb le 5 Sep 2016
No, I'm still at R2012b; not enough 'puter for later releases...
"set(hAx(2),'xaxisloc','top','xticklab',[])" command had no effect..."
If that's so, I'd say that qualifies as a bug and is worthy of reporting to TMW @ www.mathworks.com
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...

Connectez-vous pour commenter.


Thorsten
Thorsten le 5 Sep 2016
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 commentaires
Booker
Booker le 7 Sep 2016
Modifié(e) : dpb le 7 Sep 2016
Thanks for investing the time sharing your solutions.
Perhaps it's my R2105a running on Windows 7 Pro but I did not receive any luck using the following suggested command:
x = [1:100];
y = randn [100:1];
hAx = plotyy(x,y,x,sqrt(abs(y))/pi);
ylim(hAx(2),[0 1]);
set(hAx(2),'xaxisloc','top','xticklabel',[]);
box off;
hAx(2).XAxis.Visible = 'on';
Received a syntax error for the last two lines. So changed:
box off; to box(hAx(1),’Off’);
hAx(2).XAxis.Visible = 'on'; to hAx(2).Visible = 'on';
Still losing the top xAxis after executing box(hAx(1),’Off’);
Are you people having success with this using R2015a?
v/r, Book
dpb
dpb le 7 Sep 2016
Modifié(e) : dpb le 8 Sep 2016
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by