Print vectorized graphic of patches without edges

2 Ansichten (letzte 30 Tage)
Alex Ogren
Alex Ogren am 5 Aug. 2021
Kommentiert: Alex Ogren am 9 Aug. 2021
I need to export a vectorized graphic of material data from a finite element simulation. I don't want the lines of the mesh to show, I only want the faces (whose colors correspond to a colormap of material data values). Currently, 'patch' is working well to create exactly the image I need in the MatLab figure. However, I've noticed that when I print to pdf, the image is still pixelated. I am already using the '-painters' renderer. Any tips on how to fix this would be greatly appreciated.
Attached is 'patch_plotter.m' demonstrating my issue, along with a few other things to help narrow down the issue.
In patch_plotter, ax(1,1) shows the image that I'm interested in creating a vectorized version of. Also, ax(1,3) shows that when I allow the edges to be visible, the pdf image indeed does have vectorized angled edges as desired (but like I said, I don't want the edges to be showing, and the edges also result in sloppy spikes sticking out at their endpoints).
Is it possible that the actual faces of the patches are not vectorized graphics while the edges of the patches are vectorized graphics? ( ax(2,3) strongly suggests this conclusion. )
  4 Kommentare
Alex Ogren
Alex Ogren am 6 Aug. 2021
Interesting, thanks for your comment. I'm fine not using transparency for this particular task.
As for trying other file types, I just now tried .svg and .eps; both appear to have the same issue. Thanks for the suggestion though.
Alex Ogren
Alex Ogren am 7 Aug. 2021
@Jan, ax(1,1) is the image that I'm trying to create, except that if you zoom in to the pdf, you can see that the angled edges are not vectorized, they are pixelated, which is not desired. You may have to zoom in to the pdf using Adobe Acrobat Reader (or something other than a browser tab; I can't zoom in far enough with chrome to see the pixelation).
All of the other axes are just documentation of the steps I've already taken to debug the issue:
  1. ax(1,2) shows that if I set LineStyle = 'none' instead of EdgeColor = 'none', I have the same pixelation issue.
  2. ax(1,3) shows that if I allow edges to be visible, the edges do not appear pixelated. This is what I mean by "vectorized angled edges as desired". However, I want to get rid of the edges.
  3. ax(1,4) shows that if I use EdgeColor = 'none', and I set FaceColor = 'flat' instead of FaceColor = 'interp', I have the same pixelation issue.
  4. ax(2,1) shows that if I use LineStyle = 'none', and I set FaceColor = 'flat' instead of FaceColor = 'interp', I have the same pixelation issue.
  5. ax(2,2) shows that if I assign colors to the faces instead of the vertices, I have the same pixelation issue.
  6. ax(2,3) is highly informative, and shows that if I set the LineWidth = 1e-6 (for the edges), then I (again) have vectorized edges, but pixelated faces. This suggests to me that MatLab only exports the edges of patch graphics as vectorized graphics, but exports the faces as pixelated graphics. This probably works well for people who want the edges to be visible and thick, since the vectorized edges will cover up the messy pixelation of the faces. But when the edges aren't there, or are very thin, the pixelated faces are apparent. See the image below, which is a zoomed portion of ax(2,3).

Melden Sie sich an, um zu kommentieren.

Antworten (2)

J. Alex Lee
J. Alex Lee am 7 Aug. 2021
I now believe it is because you are technically plotting 3D patches (telling Matlab there's a z-coordinate, even if they are all zero)
Extract just the x and y coordinates
patch('Faces',dat.t' + 1,'Vertices',dat.p(1:2,:)','FaceVertexCData',dat.d1','FaceColor','flat');
and a quick test looks like pdf export without any tweaks will output vector
  8 Kommentare
Jan
Jan am 9 Aug. 2021
Bearbeitet: Jan am 9 Aug. 2021
@Alex Ogren: I have to modify the code a little bit, because tiledlayout is not available in R2018b:
f = figure();
for j = 1:3
ax(j) = subplot(1,3,j);
daspect([1 1 1])
end
...
Then I get a smooth PDF file (open the image in a new tab to see its full size):
The other 2 diagrams look equivalenty.
It is time to send the question to MathWorks support team. The orphaned colored pixels are clearly a bug.
Alex Ogren
Alex Ogren am 9 Aug. 2021
I also just tried on R2018b Windows 10, and the patches are smooth and vectorized. Thank you both for your help in getting to the bottom of this!
I'm not sure who to give answer credit to since @J. Alex Lee discovered that adjacent patches are buggy, and @Jan discovered that they work in R2018b - am I allowed to accept two answers?

Melden Sie sich an, um zu kommentieren.


Dave B
Dave B am 6 Aug. 2021
Using exportgraphics might do a little better.
exportgraphics(f,'mypdf2.pdf','ContentType','Vector')
Looks better to me, although better on some of your patches than others. Cool images!
  1 Kommentar
Alex Ogren
Alex Ogren am 6 Aug. 2021
Hmm, yes, thanks Dave. It looks like the issue is less pronounced when I use exportgraphics. Here are the results I'm observing when zooming in on the same region of ax(1,1) after generating the pdf with 'print' vs. 'exportgraphics'. (I'm still looking for a true vectorized graphics solution though).
print:
exportgraphics:

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by