0
$\begingroup$

From a previous post Remove artifact of PDF images I am using the following function:

    rasterizeBackground[g_, res_: 450] := 
 ReplacePart[
  g, # -> rasterizeBackground[Extract[g, #], res] & /@ 
   Position[g, Graphics[__]]]

Which rasterize the image and leaves as vector format the axis and its ticks labels. However, if the plot has a legend like in the following plot:

(*some random data*)
data21fps = 200 {#1 #2, Sin[#1 + #2]^2} & @@@ RandomReal[{0, 1}, {100000, 2}];
f[x_] := x /. {NumberForm[y_, {w_, z_}] :> ScientificForm[y, 2]}
f21fps = Show[SmoothDensityHistogram[data21fps,
   PlotRange -> {{0, 200}, {0, 200}}, 
   ColorFunction -> "SunsetColors",
   FrameLabel -> {Text[
      Style["t2-t1", FontSize -> 14, Italic],
       FormatType -> StandardForm], 
     Text[Style["t1", FontSize -> 14, 
       Italic], FormatType -> StandardForm]},
   PlotLabel -> "FPS", LabelStyle -> {FontFamily -> "Times", 14},
   PlotLegends -> 
    BarLegend[Automatic, LegendFunction -> f, 
     LegendMarkerSize -> 368]
   , Mesh -> 0
   ], Plot[x, {x, 0, 200}], ImageSize -> 400, PlotRangePadding -> 0]
Export["f21fps.pdf",f21fps];

In this case, the legend ticks in the PDF file does not look as bright or clear as the ticks of the frame, probably because they have been rasterized like the image of the plot. Is it possible to leave the legend ticks in vector format?

Thank you very much for your help

$\endgroup$
  • $\begingroup$ I have just edited the post to change the function rasterizeBackground[] that I use. Sorry for that. $\endgroup$ – user1993416 Aug 13 '17 at 16:37
  • $\begingroup$ I don't think that the issue has anything to do with the rasterization (to verify, you can look at the PDF for a non-rasterized plot). The problem is that while Ticks and Labels of the main plot are black in the PDF output, the same does not hold for the legend (note how they're the same gray as everything inside MMA itself). This answer (and the others to that question) shows how to modify legend styles (this is not as straightforward as it seems due to some bugs) $\endgroup$ – Lukas Lang Aug 13 '17 at 16:54
  • $\begingroup$ @Mathe172 Thank you, The solution of the density plot of that link makes the ticks black. How could I make the same with the original plot and color the ticks of the frame in black too? $\endgroup$ – user1993416 Aug 13 '17 at 17:13
  • $\begingroup$ For the plot itself, the options TicksStyle, FrameStyle etc. do all work as intended. You may refer to the documentation of Graphics for a full list. $\endgroup$ – Lukas Lang Aug 13 '17 at 17:24
  • $\begingroup$ @Mathe172 Thank you very much $\endgroup$ – user1993416 Aug 13 '17 at 17:25

Your Answer

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

Browse other questions tagged or ask your own question.