Strange behavior on subplots with surf

6 visualizzazioni (ultimi 30 giorni)
Sven
Sven il 19 Feb 2015
Commentato: Sven il 20 Feb 2015
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 Commenti
dpb
dpb il 19 Feb 2015
Modificato: dpb il 20 Feb 2015
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 il 20 Feb 2015
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.

Accedi per commentare.

Risposta accettata

Andrew Newell
Andrew Newell il 20 Feb 2015
Modificato: Andrew Newell il 20 Feb 2015
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 Commenti
dpb
dpb il 20 Feb 2015
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 il 20 Feb 2015
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!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by