2
$\begingroup$

I would like to save an image as a vector graphic (.pdf), so that when I zoom in, the lines and labels remain crisp. However, the image I am saving also contains components that are generated by RegionPlot. When I save these as vector graphics, the file sizes are massive, hundreds of times larger than the vector graphics not including components generated by RegionPlot.

Is there a way to save a plot so that the labels and lines on the plot are vector graphics, but shaded regions are not? An example of the image I am trying to save is below.

enter image description here

Edit: Code used to produce this graphic is below:

linelegs[label_, legs_, pos_, cols_] := 
 PlotLegends -> 
  Placed[LineLegend[
    Table[Text[
      Style[legs[[i]], 14, FontFamily -> "Times New Roman"]], {i, 1, 
      Length[legs]}], 
    LegendLabel -> 
     Text[Style[label, 14, FontFamily -> "Times New Roman"]], 
    LabelStyle -> {GrayLevel[0.3], 14}, 
    LegendLayout -> {"Column", cols}], pos]
frameStyle[xlabel_, ylabel_, fsize_: 14] := {Axes -> None, 
  Frame -> True, AspectRatio -> 1/GoldenRatio, 
  FrameLabel -> {{Text[
      Style[ylabel, FontFamily -> "Times New Roman", fsize]], 
     Text[Style["", fsize]]}, {Text[
      Style[xlabel, FontFamily -> "Times New Roman", fsize]], 
     Text[Style["", fsize]]}}, 
  LabelStyle -> {FontFamily -> "Times New Roman", fsize}}
text[x0_, y0_, txt_, color_] := 
 Graphics[Text[
   Style[txt, color, FontFamily -> "Times New Roman", 14], {x0, y0}]]
Cell[StyleData["Print"], FontSize -> 36];
PH1 = ImplicitRegion[
   y >= 0 && y <= x (x + 2) && y >= x (x - 2) && x >= 0, {x, y}];
eps = 0.1;
Plasmon1 = 
  ImplicitRegion[
   x >= 0.403205 && x <= 1.25 && 
    y >= Sqrt[((16 \[Pi])/(3 \[Pi]^2)^(4/3) + 
        eps) + (12/5 - eps/(0.403205)^2) x^2] && 
    y <= Sqrt[((16 \[Pi])/(3 \[Pi]^2)^(4/3) - 
        eps) + (12/5 + eps/(0.403205)^2) x^2], {x, y}];
Regions1 = 
  RegionPlot[{PH1, Plasmon1}, BoundaryStyle -> None, 
   PlotStyle -> {LightBlue, LightRed}, PlotRange -> {{0, 1}, {0, 2}}, 
   AxesLabel -> {"q/\!\(\*SubscriptBox[\(k\), \(F\)]\)", 
     "\[Omega]/\!\(\*SubscriptBox[\(E\), \(F\)]\)"}, PlotPoints -> 5];

PHLines1 = 
  Plot[{x (x - 2), x (x + 2)}, {x, 0, 5}, 
   PlotRange -> {{0, 1}, {0, 2}}, ImageSize -> Large, 
   PlotStyle -> {Blue, Blue}];
PlasmonLines11 = 
  Plot[{Sqrt[(16 \[Pi])/(3 \[Pi]^2)^(4/3) + 12/5 x^2]}, {x, 0, 
    0.403205}, PlotRange -> {{0, 1}, {0, 2}}, ImageSize -> Large, 
   PlotStyle -> {Red}];
PlasmonLines21 = 
  Plot[{Sqrt[(16 \[Pi])/(3 \[Pi]^2)^(4/3) + 12/5 x^2]}, {x, 0.403205, 
    1.25}, PlotRange -> {{0, 1}, {0, 2}}, ImageSize -> Large, 
   PlotStyle -> {Red, Dashed}];
figure = Show[{Regions1, PHLines1, PlasmonLines11, PlasmonLines21}, 
  AspectRatio -> 1, frameStyle["q", "\[Omega]", 50], 
  FrameTicks -> {{{None}, None}, {{None}, None}}, ImageSize -> Large]
$\endgroup$
1
  • $\begingroup$ Welcome to MSE. Can you please post the code used to generate the plot. $\endgroup$ May 26 '21 at 22:33
3
$\begingroup$

I have found a work-around that is acceptable for my images. If Filling->Axis is used instead of RegionPlot, the image is around a factor of 100 smaller.

$\endgroup$
0
$\begingroup$

Just Use at end of your code the Export Function on figure like this you will find it in your home directory saved in PDF format

Export["plot.pdf", figure]
$\endgroup$
1
  • 1
    $\begingroup$ Thanks for your response! The issue I am having is related to the file size of such objects. When I export a file as a .pdf without the RegionPlot, the file size is ~10 KB (small, acceptable). When the file includes the regions, the size is ~10 MB. This image size is much too large for my purposes, and causes very long loading times for the documents that contain them. I am wondering if there is a way to save the lines and text as vector graphics, but the regions as something not so memory-intensive. $\endgroup$
    – user80223
    May 28 '21 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.