0

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

user1993416
  • 589
  • 1
  • 5
  • 12
  • I have just edited the post to change the function rasterizeBackground[] that I use. Sorry for that. – user1993416 Aug 13 '17 at 16:37
  • 1
    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) – Lukas Lang Aug 13 '17 at 16:54
  • @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? – user1993416 Aug 13 '17 at 17:13
  • 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. – Lukas Lang Aug 13 '17 at 17:24
  • @Mathe172 Thank you very much – user1993416 Aug 13 '17 at 17:25
  • @Mathe172 LabelStyle -> {FontFamily -> "Times", 14, Directive[Black, AbsoluteThickness[2], Opacity[1]]} makes black all ticks labels included the Legend. – user1993416 Aug 13 '17 at 17:38
  • @Mathe172 rasterizeBackground function does not work and leaves the artifacts (white lines) in the TeX file. You were right, unfortunately, seems not so easy to change the color and opacity of the legend labels. – user1993416 Aug 13 '17 at 17:52
  • @Mathe172 Sorry but I do not understand what is happening, now rasterizeBackground[] does not reduce the size of the PDF file and leave the white lines. I have made load the definitions again and repeat the same steps but does not rasterize the image. – user1993416 Aug 13 '17 at 18:02
  • @Mathe172 I have restart MMA. Now the large version of rasterizeBackground works but taking off the PlotLegend option. If I include PlotLegend none of the two definitions work rasterizing the image. – user1993416 Aug 13 '17 at 18:21
  • @Mathe172 please could you help me to solve this problem? – user1993416 Aug 13 '17 at 18:51
  • Are you sure you included both definitions? – Lukas Lang Aug 13 '17 at 18:54
  • @Mathe172 I thought I had to include just one. Do I have to include both in order? – user1993416 Aug 13 '17 at 18:56
  • Yes, you need both. The order in which you include them doesn't matter however – Lukas Lang Aug 13 '17 at 22:24

0 Answers0