Top x-axis disappeared in plotyy
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am using plotyy. It worked nicely until I added a title to the plot. Now the top x-axis has disappeared. What to do in order to make it visible?
15 Kommentare
dpb
am 1 Feb. 2016
Bearbeitet: dpb
am 2 Feb. 2016
You still didn't give enough data to be able to easily recreate anything that matches -- don't know what the ranges are so can't do anything meaningful in trying to match what is causing your issues.
I do suspect it has to do with the previous comment but until can duplicate the symptom can't really provide a solution.
At a minimum, the ranges of each of the vectors you're plotting would suffice; simplest would be to have a complete sample can just run directly using (say) some random values over those ranges. Also, what are the bare minimum lines required before the symptom appears the x|ylabel I presume make no difference? Let's pare it down to the essence, iow.
Also, you didn't hit the "Attach" button in lower RH corner apparently; your figures didn't show up.
I had a much longer reply including trying some to try to guess-plicate the results but we're rural and have had a series of power outages this AM and it got me last time so I gave up.
I'm willing to help but give me some help here... :)
ADDENDUM
Besides the x ranges being same, it would likely help if the y ranges are consonant with your data as well. As said before, I'm suspecting it's tied in with the use of hold on as well as the changing of the axis limits; seeing it operate on those same limits is, perhaps, key in both reproducing and solving the problem. At least, I'm not willing to spend time trying without the detail I think needed to have a chance of success, particularly when it's would be so trivial to do so...
ADDENDUM 2
BTW,
xup=round(max(x));
will always be < max(x) unless max(x) is integer-valued or the fractional part is >0.5. So when your dx is 0, your x-limits won't cover the full data set. You're probably looking for
xup=ceil(max(x));
for positive values of x.
Also, you don't define the ylim variables you computed(?) I suppose also somewhat similar to the x-axis ones.
Again, as I've suggested a number of times, create a small, reproducible in its entirety w/o relying on something else we don't have example and paste it in.
Shouldn't take more than 10 lines or so...
ADDENDUM 3 :)
BTW, if you do post an example case and don't hear back for a while, "not to worry!". My next couple of days are pretty much spoke for so won't be having much time until later in the week...I'll try to catch a moment to check and if it seems easy-peasy maybe, but if it is going to take some digging, it'll likely have to wait...
Akzeptierte Antwort
dpb
am 2 Feb. 2016
Bearbeitet: dpb
am 3 Feb. 2016
OK, now we have enough to diagnose the real problem -- turns out didn't need so much but without something that could run to illustrate your concern didn't know exactly what the issue really, really was/is...
Anyway,
That's the symptom I described "way back when"... :)
A) box on will restore the top x-axis if it isn't displayed. As noted, why it's left 'on' in some instances and 'off' in others is buried in the internals of HG that have no way to ascertain but restoring it to 'on' will fix the issue. If you want the axis shown, then it can't hurt to force it irrespective. This one is, as I think I mentioned also, probably worth an official bug/interpretation request to TMW.
B) This is the other one I previously outlined. Unfortunately, you can't eliminate the dual tick marks on the right axes as long as you force having a different number of tick marks and non-consistent spacing because there are two independent axes objects and TMW didn't include the facility to separate the tick marks on the LH and RH axes (or top or bottom either, for that matter) as independent properties; they're both on or both off.
ADDENDUM It just dawned on me the reason for A -- it's because the internal logic is "smart". It recognizes the discord between y tick mark locations on the two axes and so turns off the box for both axes so the duplicated and non-matching y-ticks don't confuse. BUT, this has the side-effect of turning off the upper x-axis as well.
I turned your function into a script so had access to the variables at the command line (or you can just use the debugger and stop inside) but try
set(ax(2),'box','on')
to see what happens, then toggle it back off and switch axes.
I don't think the lengths have anything to do with it other than whether by happenstance you end up with the same number of y ticks or not; that will, I'm virtually certain, be the key point.
I've got the "high-priced consultant" coming in at noon; gotta' run now but I'll try to check back later on to see if you've other issues/concerns.
Oh, one last thought -- I don't have time now to do it, if you really, really, really must have the top x axis, you can either just draw the tick marks if that's all needed (no labels) or add yet another axis object that overlays these with x-axis at the top. I think that'll work altho there may be some issues of transparency to make all levels show thru. To see "issues", try
axes(ax(2))
axes(ax(1))
and likely the legend will become occluded.
Oh, one last thought, given your moniker... :) I've complained for almost 30 yr and TMW hasn't fixed it yet, but the mismatched formatting on the axis tick labels just bugs me no end. I'd add
ytk=get(ax(2),'ytick').'; % retrieve tick values
set(ax(2),'yticklabel',num2str(ytk,'%.1f')) % set with consistent formatting
You can, of course, dispense with the temporary ytk by folding into the num2str argument but it's far easier to write initially as above. BTW, do NOT forget the transpose; you won't like the results otherwise! :)
Good luck, hope that 'splains the problems/issues...they're pretty much inherent w/ HG. An enhancement request never hurts.
ADDENDUM
As is so often the case, the real solution just came to me--
set(ax(2),'xaxislocation','top','xticklabel','')
and you can "have your cake and eat it, too!" :)
This will put the RH axis at the top and have the same net effect on the top tick marks as does 'box','on' but without the side effect of turning on the other ytick. Setting the tick labels to null string keeps them from showing up; if leave on you'll need to make that fixup before using title so it is written above them, otherwise they'll clash for room.
6 Kommentare
dpb
am 3 Feb. 2016
OK, wasn't wanting to leave you with a feeling of dissatisfaction if possible to resolve a question.
Re: the moniker, I was just commenting on it implying desire for "clean" graphics which is perfectly reasonable objective, particularly if one is trying to prepare presentation-ready graphics. The example of the mismatched formatting for tick labels is one that bugs me so that feel some tendency in that regards myself. :) My use of Matlab was pretty much the same way; I've since retired from active duty and this is "play" to keep in hand and that I simply do enjoy fiddling with such issues to try to find these workarounds as an intellectual challenge if nothing else.
Weitere Antworten (2)
dpb
am 3 Feb. 2016
Bearbeitet: dpb
am 3 Feb. 2016
The subsequent answer buried at the end of the long previous discussion is, I think, so significant I'll repost it here alone--
The real solution just came to me--
set(ax('box','off') % turn box off both axes for sure...
set(ax(2),'xaxislocation','top', ...
'xticklabel',[]) % move RH x axis, clear tick labels
and you can "have your cake and eat it, too!" :)
This will put the RH axis at the top and have the same net effect on the top tick marks as does 'box','on' but without the side effect of turning on the other ytick. Setting the tick labels to null string keeps them from showing up; if leave on you'll need to make that fixup before using title so it is written above them, otherwise they'll clash for room.
With this, I created a figure with two subplots, one with and one without the upper labels...

In the close spacing of the subplot the upper title still interferes with the labels altho it didn't as a single plot if added after the setting of the xaxis position property.
Also with subplot I had to set 'box','off' explicitly on LH axis whereas for the full-size plot the internal logic left both 'off'.
I dropped the legend for lack of room and of no real interest to the question at hand, anyway...
8 Kommentare
dpb
am 4 Feb. 2016
Just as sanity check I redid the test here from command line...
>> ax1=plotyy(xextrap,yextrap,xextrap,tion);
>> get(ax1,'xaxisloc')
ans =
'bottom'
'bottom'
>> set(ax1(2),'xaxisloc','top')
>> get(ax1,'xaxisloc')
ans =
'bottom'
'top'
>> set(ax1,{'xaxisloc'},{'top';'bottom'})
>> get(ax1,'xaxisloc')
ans =
'top'
'bottom'
>> set(ax1,{'xaxisloc'},{'bottom';'top'})
>> get(ax1,'xaxisloc')
ans =
'bottom'
'top'
>>
Swapping back and forth makes no difference, both are viewable either way and the above is the following figure...
<<

>>
dpb
am 4 Feb. 2016
Oh, just one last thought...
What does
get(ax,'color')
return when x-axis not visible on the base trial? Wonder if by some chance the 'none' setting for the second axes could have gotten mucked upon....but then would think the lines wouldn't show up on ax(1), either....real long shot.
Image Analyst
am 4 Feb. 2016
Perhaps you'd like this, or an adaptation of it:

4 Kommentare
Image Analyst
am 4 Feb. 2016
Well, it was worth a shot. I didn't read the whole extensive discussion above, so I don't know the background, but it sounds like you want plotyy and that is what dpb is working with you on. Good luck.
dpb
am 4 Feb. 2016
Bearbeitet: dpb
am 4 Feb. 2016
I just looked at the source for plotxx and it's a very simple two-axes routine the guts of which boil down to
ax(1)=gca;
....
ax(2)=axes('Position',get(ax(1),'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','r','YColor','k');
set(ax,'box','off')
the settings for the 2nd axis vis a vis the first are identical as to what have been doing with plotyy (other than the hardcoded axis colors which is pretty user-belligerent there).
It's looking to me more and more like there's an issue with HG2. Do you have it, IA? Can/would you try perfectionist's sample above if so? Given the longwinded conversation, here's the link to the comment where the basic function was posted and there's a link to the data file at the bottom so you don't have too much hunting to do to find it.
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!