Strange behavior on subplots with surf

4 次查看(过去 30 天)
Today I noticed a very strange behavior in a rather complex creation of a figure. To see the actual problem, I broke down the code to the essential parts: I create a figure with two subplots in one figure. But whenever I add a surface plot to the second subplot (instead of a normal 2D plot) the properties of the first subplot change. Please run the following code, compare the figures to see the differences:
x=1:20;
y1=randn(20,1);
y2=ones(20,1);
figure;
subplot(2,2,[1,2]);
plot(x,y1,x,y1);hold on;
plot(x,y2,'--b','LineWidth',2); hold off;
subplot(2,2,[3,4]);
surf(x,x,y1*y1','LineStyle','none');
figure;
subplot(2,2,[1,2]);
plot(x,y1,x,y1); hold on;
plot(x,y2,'--b','LineWidth',2); hold off ;
subplot(2,2,[3,4]);
plot(x,y1);
Is there an explantion for this change (especially for the dashed line)? How can I change the properties of the second figure to the unintended and changed properties of figure 1?
I use Matlab R2013b! Thanks for the support!
  2 个评论
dpb
dpb 2015-2-19
编辑:dpb 2015-2-20
No klew...it acts the same way in R2012b(*), btw, so it's not the new graphics engine.
For some reason the lines are rendered differently despite style and width parameters being the same. I went side-by-side and retrieved the handles to the two lines and set the properties manually to a range of line widths and the rendering still isn't the same between the two. I could observe no properties that were different that are visible.
Looks like an official support topic at www.mathworks.com
BTW, why use
subplot(2,2,[1,2]);
instead of the syntactically simpler
subplot(2,1,1);
for full-width, two-high suplots??
ADDENDUM
(*) Just out of curiosity, I tried the earliest version I have installed (R11). The difference isn't quite as noticeable but they're still different. With it the apparent width is almost indistinguishable between the two but there's a notable difference in the length of the dashed line segments between the two.
Really, really, bizzaro!!! Be interesting to hear what TMW has to say on this one...
Sven
Sven 2015-2-20
Thanks for your respond :)
The "subplot(2,2,[1,2])" syntax is from my more complex code. But you are right, it is not needed here.

请先登录,再进行评论。

采纳的回答

Andrew Newell
Andrew Newell 2015-2-20
编辑:Andrew Newell 2015-2-20
It appears that surf chooses OpenGL for the renderer (see Figure properties for an explanation of the renderer). Since this is a property of the entire figure, it redraws the first subplot as well. You could add the line
set(gcf,'Renderer','painters')
to restore the default renderer for the first figure.
  3 个评论
dpb
dpb 2015-2-20
Sure, you can use renderer of choice...
set(gcf,'renderer','OpenGL')
I hadn't thought of the renderer itself, Sven, good catch. I shoulda' thunk of it as a likely culprit when the styles changed.
Sven
Sven 2015-2-20
Thank you very much Andrew!
That is actually a good way to increase the quality of printed figures. Especially when it comes to dashed lines!

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by