I am using the following Mathematica snippet to generate a contour plot:
Needs["MaTeX`"]
press[x_, fo_] = (fo + (18.369*Exp[-2.491*x]))/(29.512*Exp[-9.691*x])
fs[x_] = (7.14286/x + 51.0204 Log[7. - 50. x] - 51.0204 Log[x])/10
plot = ContourPlot[press[x, fo], {x, 0.05, 0.35}, {fo, 0, 80},
PlotRange -> {2, 8},
RegionFunction ->
Function[{x, fo, press}, If[x < 0.14, fs[x] < fo, 0 < fo]],
BoundaryStyle -> Black,
Contours -> {2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8},
FrameLabel ->
MaTeX[{"Clearance \, (mm)\, stick-slip", "Force \, (N)"}],
PlotLegends ->
Placed[
BarLegend[{Automatic, {2, 8}}, LegendLayout -> "Row",
LegendMarkerSize -> {50, 15},
LegendFunction ->
(Framed[#, RoundingRadius -> 5,
Background -> Opacity[0.7, White]] &),
LegendMargins -> 5,
LegendLabel -> Placed[MaTeX["Pressure \, (Bar)"], Below],
BaseStyle -> {FontFamily -> "Times", FontSize -> 8}], {0.75,
0.75}],
LabelStyle -> Directive[Black, Bold, Medium],
AspectRatio -> 1/2,
BaseStyle -> {FontFamily -> "Times", FontSize -> 10}]
The plot renders correctly in the Mathematica notebook, although I need to manually stretch it to ensure everything displays properly. When exporting as a PNG using the following command:
Export[FileNameJoin[{NotebookDirectory[], "output.png"}], plot, "PNG",
ImageResolution -> 600, ImageSize -> 3000]
The output seems fine.
However, when I export as a PDF with Export[FileNameJoin[{NotebookDirectory[], "output.pdf"}], plot, "PDF", ImageResolution -> 600, "AllowRasterization" -> True]
to achieve a vectorized output, I encounter an issue where the plot shows an unwanted triangular mesh or grid pattern:
and the legend is out of the plot partially!
I tried increasing PlotPoints
and MaxRecursion
, which led to much longer processing times and a significantly larger PDF file size without resolving the issue.
My goal is to generate a smooth and clean vectorized output in PDF format without the triangular mesh artifacts, preferably with reasonable processing time and file size.
Is there a way to achieve this, or any alternative approach I should consider?
SetOptions[$FrontEndSession, Antialiasing -> Automatic]
at the top of my code but it did not solve the problem. And the legend is still out of bounds! $\endgroup$