Changing the current axes causes a line that is a child on another axes to disappear.
이전 댓글 표시
Hello, I have a plot with two axes objects. On one axes, I use plot to plot an x-y plot. On the other axes, I use the line function to draw a line. When I set the current axes to the first one, the second plot (line) disappears. How do I fix this? BTW, I can get the line back by setting the 2nd axes as the current one. Thanks.
댓글 수: 2
Walter Roberson
2015년 12월 30일
What is
get(gcf, 'Renderer')
showing for you?
Also is the line drawn a 3 dimensional line?
Suresh
2015년 12월 30일
채택된 답변
추가 답변 (2개)
dpb
2015년 12월 30일
0 개 추천
When you create the second axes, use 'Color','none' to make the first axes also visible. See the example of Using multiple-x-axes-and-y-axes
Walter Roberson
2015년 12월 30일
0 개 추천
Or it could be a bug.
댓글 수: 5
Suresh
2015년 12월 30일
편집: Walter Roberson
2015년 12월 30일
Kelly Kearney
2015년 12월 30일
You've created two axes, the first with a white background and the second with a clear background. When you place the first on top (as occurs when you make it the current axis), the white background hides the line in the lower axis.
If you plan on switching between the two axes, make sure neither have a background color.
OK, that's order dependency and the visibility issue occurs in R2012b as well (I illustrated w/ plotyy to see if there were anything being done internally that helped besides the 'color','none' trick).
There's one difference, however, with R2012b I could place a data cursor on either line w/o having to select the axes first; however, if did make LH axes current then the hiding feature came thru.
You can see both lines with the undesirable effect that the background becomes the default by setting both axes 'color' property to 'none'. You can then fix that with the resulting undesirable effect on the outside frame also changing by
set(gcf,'color',[1 1 1])
I don't know there's a way to independently set the area outside the axes bounding box, though...
All in all, just another of the "warts" in HG that generally doesn't bite too much, but when it does...but maybe a true whizard in HG will know the innards well enough to post a workaround.
dpb
2015년 12월 30일
I wouldn't go so far as to say they were "suggestions"; more like simply "observations" with another/earlier revision to try to isolate what might have been introduced with HG2 as a bug vs what was earlier behavior.
To be clear, in the following sequence under R2012b--
figure
hAx1 = axes('XAxisLocation', 'top', 'YAxisLocation','left');
plot(hAx1, 1:10, 1:10);
hAx2 = axes('XAxisLocation', 'top', 'YAxisLocation','right','color','none');
line(1:10, 0.2 * (1:10).^2, 'parent', hAx2, 'color', 'red');
axes(hAx1) % here hAx2 is occluded
set(hAx1,'color','none') % both lines appear on gray background
set(gcf,'color','w') % now whole figure bkgd is white both lines show
axes(hAx2) % toggling which axis is gca makes no difference
axes(hAx1) % on visibility
If I use the above I do still have the symptom that can't use the data cursor except on the current axis in focus.
Now, if instead of plot and line on the two axes, I use
figure
hAx=plotyy( 1:10, 1:10,1:10,0.2 * (1:10).^2);
I (a) see both lines on white background, and (b) can use data cursor on each line w/o physically switching back and forth the current axis.
HOWEVER,
axes(hAx(1)) % does cause the RH axis line to be occluded
axes(hAx(2)) % gets it back visible
so there's still something regarding order and all which isn't fully clear as to the details of what's going on internally. Particularly, I can't at this time grok the difference between the two cases for the cursor accessibility; as far as I knew all plotyy did was hide the creation of the 2nd axes for you and align the tick marks to be "pretty" by matching the number of ticks on each y-axis.
It used to be an m-file; now it's a p-file so can't see the innards; mayhaps they've used some other undocumented "tricks" as well, now.
카테고리
도움말 센터 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!