10
$\begingroup$

I recently upgraded from Mathematica 11 to Mathematica 12.1.0.0 . I understand there were some UI changes to accommodate high resolution monitors. I'm not sure if this issue is related to that. I am running on Windows 10. Below is a test script.

data = Table[RandomReal[{0, 1}], 100, 3];
plot = ListPointPlot3D[data, PlotStyle -> Black, LabelStyle -> {FontFamily -> "Helvetica", FontSize -> 12, Black}, AxesStyle -> {Black, Thin}, ImageSize -> 240];
Export[NotebookDirectory[] <> "plot.png", plot, ImageResolution -> 500]

Here is the image this produces on my computer.

Here is the images produced on a colleagues computer. He uses Mathematica 12.0.0.0 on a Mac.

As you can see. Mine is a much lower quality. I would export this as a vector graphic, but I believe Mathematica intentionally rasterizes 3D graphics to minimize file size.

I've also tried exporting as a pdf with similar (really worse) result. I've also tried right-clicking to save the graphic, again as both png and pdf. In the case of the pdf, the save dialogue lets you pick an export quality and it still produced a low quality image.

Additionally I also tried rasterizing before passsing to Export[] but nothing changed.

Export[NotebookDirectory[] <> "plot.png", Rasterize[plot, ImageResolution -> 500]]

The size of the image is also odd. I thought the image would by 3.33in wide but it is only 2.5in. I thought it would be 3.33 because 240/72 = 3.33. In fact, the image my colleague produced with the same script is 3.33in!

I thought it may be related to this question. But after doing what they suggested I still end up with low quality images. It does appear that to get the proper size image from ImageSize I need to use 96 instead of 72. But then that messes up the text size!

Does anyone have any insight into this issue?

$\endgroup$
7
  • $\begingroup$ I would upgrade to 12.1.1. I just tried your example in 12.1.1 and it exports at 1667x1288 @ 500dpi. Which is 3.33"x2.58". $\endgroup$
    – ihojnicki
    Sep 11, 2020 at 23:06
  • $\begingroup$ If possible, I recommend upgrading to the latest version (12.1.1 June 19 or later). I had a lot of resolution problems as well in 12.1.0. Idk if it will work for you one Windows, but my workaround was Export[“filename.png”, plot, ImageResolution -> 300, RasterSize -> 4000]. $\endgroup$
    – MassDefect
    Sep 12, 2020 at 0:38
  • $\begingroup$ Thanks for the reply @ihojnicki. I uninstalled 12.1.0.0 ad installed 12.1.1.0. Unfortunately I get the same results as I did before. $\endgroup$ Sep 12, 2020 at 1:32
  • $\begingroup$ @MassDefect I tried what you suggested. The image quality is better but the dots are still not circular and the image size is still not correct (now it's 13.3 in). I believe what you put does explicitly is make a crazy high quality raster then downscale it to whatever you put in ImageResolution. $\endgroup$ Sep 12, 2020 at 1:42
  • 1
    $\begingroup$ @ihojnicki, yes it was set to 75%. I changed it back to 100%. I'm starting to have trouble comparing the qualities, but at the very least the image size is correct now. I'm so confused. Why would the default notebook zoom make such an overwhelming difference? $\endgroup$ Sep 12, 2020 at 14:19

1 Answer 1

1
$\begingroup$

You can use ImageSize option of Rasterize and increase the value of FontSize in ListPointPlot3D.

  1. Compute scaling factor:
In[3]:= sf = ImageDimensions[Rasterize[plot, ImageSize -> 1000, ImageResolution -> 500]] / ImageDimensions[Rasterize[plot, ImageResolution -> 500]] // N

Out[3]= {4.16617, 4.24099}
  1. Adjust FontSize, TicksStyle and AxesStyle:
style = ConstantArray[{Black, Thick}, 3];
plot2 = ListPointPlot3D[data, PlotStyle -> Black, LabelStyle -> {FontFamily -> "Helvetica", FontSize -> 12 * sf[[1]], Black}, TicksStyle -> style, AxesStyle -> style, ImageSize -> 240];
  1. Generate PNG file:
Export[NotebookDirectory[] <> "plot.png", Rasterize[plot2, ImageSize -> 1000, ImageResolution -> 500]]
$\endgroup$
3
  • $\begingroup$ I appreciate the response. So ImageSize changes the dimensions of the image and ImageResolution changes the quality. So by changing the size of the image and keeping ImageResolution the same you can artificially produce a higher quality image. A 13.3" image at 500 is the same as a 3.3" image at a much higher quality. This is a fine work around, but the text, marker, and tick mark sizes will be incorrect. Is there a precise way to rescale the text and marker sizes at this new image? $\endgroup$ Sep 12, 2020 at 14:24
  • $\begingroup$ I have updated my answer. $\endgroup$ Sep 13, 2020 at 15:48
  • $\begingroup$ I appreciate the update. Your use of ImageDimension was helpful. It helped me confirm my issues were due to my Global Magnification (GM) being set to 75% (it can be found in preferences). The dimensions set by ImageSize apparently depends on Global Magnification. Plot[x,{x,0,1}, ImageSize->240] at GM = 75% is 2.5 inches. Plot[x,{x,0,1}, ImageSize->240] at GM = 100% is 3.3 inches. $\endgroup$ Sep 13, 2020 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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