2

For example

test = DensityPlot[x, {x, 0, 1}, {y, 0, 1}, PlotRange -> All, 
   FrameLabel -> {"w", "E"}, LabelStyle -> Directive[13, Black]];
Export["test.pdf", Grid[{{test, test}}], "AllowRasterization"->True, ImageResolution -> 600]

The exported pdf (I intentionally used rasterization option, because I want rasterization) is like

enter image description here

However, if you set Bold LabelStyle

test = DensityPlot[x, {x, 0, 1}, {y, 0, 1}, PlotRange -> All, 
       FrameLabel -> {"w", "E"}, LabelStyle -> Directive[Bold,13, Black]];
Export["test.pdf", Grid[{{test, test}}], "AllowRasterization"->True, ImageResolution -> 600]

the resulting font is rough

enter image description here

What is wrong? How to correctly setting Bold?

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
matheorem
  • 17,132
  • 8
  • 45
  • 115

1 Answers1

4

What seems to work is doing the Rasterization by hand

img = Rasterize[
   GraphicsGrid[{{test, test}}],
   ImageResolution -> 600
   ];
Export["test.pdf", img]

enter image description here

Note that I use GraphicsGrid instead of Grid. Otherwise I would have gotten this mess:

enter image description here

Edit

Since I had to cope with a similar problem yesterday:

You may also try to export to svg and to use ffmpeg (version 3.4.1 or higher) to do the rasterization. Apparently, the svg exporter treats Grid in the desired way.

test = DensityPlot[x, {x, 0, 1}, {y, 0, 1}, PlotRange -> All, 
   FrameLabel -> {"w", "E"}, LabelStyle -> Directive[13, Black, Bold]];
g = Grid[{{test, test}}];
file = Export["test.svg", g]
file = FileNameJoin[{If[
     StringLength[DirectoryName[file]] == 0,
     Directory[],
     DirectoryName[file]
     ],
    FileBaseName[file]}];
message = Import[
  StringJoin[{
    "! /opt/local/bin/ffmpeg -width 1024 -y -i ",
    file, ".svg ",
    file, ".png ", " 2>&1"
    }],
  "Text"
  ]
Import[file <> ".png"]

enter image description here

Note that you have to specify the image's resolution as an option of ffmpeg. I use -width 1024 to specify the absolute number of pixels in x direction should be 1024; the number of pixels in y directions is computed from that and from the aspect ration of the bounding box in the svg.

A word of warning: In the past, I also encountered numerous problems with the svg exporter. So no guarantee for anything.

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
  • Hi, Henrik Schumacher. First an upvote : ) However, it has subtle issue. it brings back to my recent post https://mathematica.stackexchange.com/q/172192/4742. GraphicsGrid can not replace Grid in any case. Because, Grid can scale with content, while GraphicsGrid can not... – matheorem May 01 '18 at 09:12
  • Try my example in my previous post like this plot = Plot[x, {x, 0, 1}, Frame -> True, AspectRatio -> 1, ImageSize -> 100]; plots = GraphicsGrid[{{GraphicsGrid[Table[plot, {i, 2}, {j, 2}]], Plot[x, {x, 0, 1}, PlotLabel -> "yyy"]}}]; newplots = GraphicsGrid[{{Show[plot, ImageSize -> 200, AspectRatio -> 2], plots}}] – matheorem May 01 '18 at 09:12
  • Hi, Henrik Schumacher. Sorry for late comment. I just tried ffmpeg. I don't know if it is version issue. But my ffmpeg seems doesn't support -width option, it will complain "Unrecognized option 'width'". And if I simply run ffmpeg -i test.svg test.png, it will complain "Decoder (codec svg) not found for input stream". I can not find a solution. My ffmpeg version is 3.4, what is your version? – matheorem May 08 '18 at 08:18
  • Oh, I just found a bug for svg exporter. Try Export["R:\\test.svg", ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]]. The exported svg has many white lines – matheorem May 08 '18 at 08:32
  • My ffmpeg version is 3.4.1. I run it on macOS High Sierra. – Henrik Schumacher May 08 '18 at 08:32
  • The white lines are a typical problem when exporting contourplots to vector graphics formats. Also happens with pdf. This has been addressed several times on this site; just have a look. – Henrik Schumacher May 08 '18 at 08:34