2
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Oh my, Export is so broken. It is not as severe on my version 11.3 for macos but as long as I export a Grid, all settings for ImageSize and ImageResolution are effectively ignored. Export the graphic test alone seems to work fine. $\endgroup$ – Henrik Schumacher May 1 '18 at 6:55
  • $\begingroup$ What version of MMA do you use? It occurs to me that versions 10.0.x have such symptoms. $\endgroup$ – Αλέξανδρος Ζεγγ May 1 '18 at 7:18
  • $\begingroup$ @HenrikSchumacher Yeah, I know it is only occured in Grid. And I am using 11.2 windows. And I have wasted several days on Export issue recently... $\endgroup$ – matheorem May 1 '18 at 7:20
  • $\begingroup$ I don't observe this problem with Mathematica 11.3 on Windows 7 x64. $\endgroup$ – Alexey Popkov May 8 '18 at 9:13
4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Hi, Henrik Schumacher. First an upvote : ) However, it has subtle issue. it brings back to my recent post mathematica.stackexchange.com/q/172192/4742. GraphicsGrid can not replace Grid in any case. Because, Grid can scale with content, while GraphicsGrid can not... $\endgroup$ – matheorem May 1 '18 at 9:12
  • $\begingroup$ 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}}] $\endgroup$ – matheorem May 1 '18 at 9:12
  • $\begingroup$ 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? $\endgroup$ – matheorem May 8 '18 at 8:18
  • $\begingroup$ 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 $\endgroup$ – matheorem May 8 '18 at 8:32
  • $\begingroup$ My ffmpeg version is 3.4.1. I run it on macOS High Sierra. $\endgroup$ – Henrik Schumacher May 8 '18 at 8:32

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.