필터 지우기
필터 지우기

Painters doesn't render line styles properly

조회 수: 10 (최근 30일)
Jaime Abad Arredondo
Jaime Abad Arredondo 2022년 8월 23일
편집: Jaime Abad Arredondo 2023년 10월 11일
Hey there! I'm trying to export a figure as a pdf, and as such I set painters as the renderer for my figure. However, I don't seem to be getting the correct linestyles that I specify. Here's a mwe of what is happening:
x=linspace(0,1,100);
[X,Y]=meshgrid(x);
Z=peaks(100);
set(gcf,'Renderer','painters');
hold all
surf(X,Y,Z)
shading interp
contour3(X,Y,Z+1,[1,1],'LineStyle','--','LineWidth',1,'LineColor','w')
contour3(X,Y,Z+1,[2,2],'LineStyle','-.','LineWidth',1,'LineColor','w')
view(2)
As you can see the plot shows solid lines. By increasing the linewidth I see that the lines are actually dashed and dotted, but as they are they are pretty unusable. Anyone knows how to fix this issue?
  댓글 수: 3
Rik
Rik 2022년 8월 23일
Perhaps using plot to create the lines might work better?
Jaime Abad Arredondo
Jaime Abad Arredondo 2022년 8월 23일
It seems like the behavior of plot3 and contour3 is the same... See the result below. I have also added the same figure generated with smaller matrices and you can see that the lines appear properly. I might have to resample the contour lines with less data points... A bit of a bummer considering that with openGL it works straight away.
figure(1)
clf
set(gcf,'Renderer','painters');
tiledlayout(1,2)
N0v=[20,100];
for j=1:length(N0v)
nexttile()
x=linspace(0,1,N0v(j));
[X,Y]=meshgrid(x);
Z=peaks(N0v(j));
hold all
surf(X,Y,Z)
shading interp
levels=[0,1];
cs={'w','r'};
lst={'-.','--'};
for i=1:length(levels)
M=contour3(X,Y,Z,levels(i)*[1,1],'LineColor','none','Visible','off');
c=1;
aux=true;
while aux
height_contour=M(1,c);
NP_cont=M(2,c);
x=M(1,c+(1:NP_cont));
y=M(2,c+(1:NP_cont));
z=ones(size(x))*(height_contour+1);
plot3(x,y,z,...
'LineStyle',lst{i},'LineWidth',1,...
'Color',cs{i})
c=c+NP_cont+1;
if c>size(M,2)
aux=false;
end
end
end
view(2)
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Shivam
Shivam 2023년 10월 11일
편집: Shivam 2023년 10월 11일
Hi,
From the information you have provided, I understand that you are facing an issue getting the correct linestyles while setting the renderer for the figure as “painters.” Also, setting the renderer as “painters” works for you in the case of small matrices.
Since you have tried “OpenGL,” you can also use “zbuffer” to get the correct linestyles. Here is the sample code:
set(gcf, 'Renderer', 'zbuffer');
You can refer to the following documentation to know more about set and Renderer:
  1. https://www.mathworks.com/help/releases/R2023a/matlab/ref/set.html
  2. https://www.mathworks.com/help/releases/R2023a/matlab/ref/matlab.ui.figure-properties.html#prop_Renderer
I hope it helps.
  댓글 수: 2
Rik
Rik 2023년 10월 11일
Wouldn't a doc page about the renderers make more sense as a reference?
Jaime Abad Arredondo
Jaime Abad Arredondo 2023년 10월 11일
편집: Jaime Abad Arredondo 2023년 10월 11일
Thanks for the suggestion!
As I see from the internet, z-buffer is not supported by matlab from release 2014b. In fact, when looking at the renderers page from mathworks, the term 'z-buffer' doesn't appear on the page. Setting it as a render engine still works though (see below). However this doesn't solve the issue at hand, since z-buffer generates the images by rasterizing, and therefore can't be properly exported as a vector file.
x=linspace(0,1,1000);
[X,Y]=meshgrid(x);
Z=peaks(1000);
set(gcf,'Renderer','zbuffer');
hold all
surf(X,Y,Z)
shading interp
contour3(X,Y,Z+1,[1,1],'LineStyle','--','LineWidth',1,'LineColor','w')
contour3(X,Y,Z+1,[2,2],'LineStyle','-.','LineWidth',1,'LineColor','r')
view(2)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by