3
$\begingroup$

The following code illustrates the difference in quality between text in Output, PlotLabel in Plot3D, and PlotLabel in Plot (same label text for comparison). [MMA 11.0.1 on Win 10 64-bit]. The quality difference is especially bad at 100% scaling, but font rendering is visibly different even at 300%. On Windows, Calibri illustrates the minimal visual difference - it's even worse for serif fonts such as Times New Roman (I swear the kerning is different too between Plot3D and Plot, but it could be a visual side effect of the different rendering.)

fontF = "Calibri";
{Style["Softmax", Bold, FontFamily -> fontF, 18], 
 pl3d = Plot3D[SoftmaxLayer[][{x, y}], {x, -2, 2}, {y, -2, 2}, 
   ColorFunction -> "DarkRainbow", 
   PlotLabel -> 
    Pane[Style["Softmax", Bold, FontFamily -> fontF, 18], 
     Alignment -> Left, ImageSize -> {180, 40}], 
   NormalsFunction -> None, ImageSize -> Small] , 
 Plot[x^2, {x, -2, 2}, 
  PlotLabel -> 
   Pane[Style["Softmax", Bold, FontFamily -> fontF, 18], 
    Alignment -> Left, ImageSize -> {180, 40}], ImageSize -> Small]}

enter image description here

The questions are: why, and how to overcome it?

(I have a series of plots for potential publication some of which are Plot and some of which are Plot3D and side by side, the difference is noticeable and unacceptable... I need to fix it)

Update

At @MichaelE2's suggestion, moving the labelling outside the Plot3D delivers the expected quality, so we have a way around the issue; the only remaining question is why PlotLabel is defective in Plot3D.

Labeled[Plot3D[SoftmaxLayer[][{x, y}], {x, -2, 2}, {y, -2, 2}, 
  ColorFunction -> "DarkRainbow", NormalsFunction -> None, 
  ImageSize -> Small], 
 Pane[Style["Softmax", Bold, FontFamily -> fontF, 18], 
  Alignment -> Left, ImageSize -> {180, 40}], Top]

enter image description here

$\endgroup$
6
  • $\begingroup$ What happens when you export the graphs? $\endgroup$
    – yarchik
    May 1, 2021 at 20:25
  • $\begingroup$ Relevant mathematica.stackexchange.com/a/1546/9469 $\endgroup$
    – yarchik
    May 1, 2021 at 20:30
  • $\begingroup$ How about Labeled[Plot3D[SoftmaxLayer[][{x, y}], {x, -2, 2}, {y, -2, 2}, ColorFunction -> "DarkRainbow", NormalsFunction -> None, ImageSize -> Small], Pane[Style["Softmax", Bold, FontFamily -> fontF, 18], Alignment -> Left, ImageSize -> {180, 40}], Top ]? $\endgroup$
    – Michael E2
    May 1, 2021 at 22:49
  • $\begingroup$ @yarchik Yes, I have now exported to png and the result is the same. $\endgroup$ May 2, 2021 at 9:15
  • $\begingroup$ @MichaelE2 Yes, that worked - see update above. Thx! (If I had to guess why quality is off, I would say, Plot3D is rotating both plot and label initially - and then unrotating the label, but accumulating a non-zero 3D error in the process. Or, b) ______ ;) ) $\endgroup$ May 2, 2021 at 9:23

1 Answer 1

0
$\begingroup$

The following works on my Mac in V12.2 and on the OP's Windows in V11.0.1. The fix is to use Labeled instead of PlotLabel.

fontF = "Calibri";
{Style["Softmax", Bold, FontFamily -> fontF, 18], 
 pl3d = Labeled[
   Plot3D[SoftmaxLayer[][{x, y}], {x, -2, 2}, {y, -2, 2}, 
    ColorFunction -> "DarkRainbow", NormalsFunction -> None, 
    ImageSize -> Small],
   Pane[Style["Softmax", Bold, FontFamily -> fontF, 18], 
    Alignment -> Left, ImageSize -> {180, 40}],
   Top
   ],
 Plot[x^2, {x, -2, 2}, 
  PlotLabel -> 
   Pane[Style["Softmax", Bold, FontFamily -> fontF, 18], 
    Alignment -> Left, ImageSize -> {180, 40}], ImageSize -> Small]}

I think the reason it works is that Graphics3D/Graphics3DBox is rasterized, and the difference is whether the label is inside or outside Graphics3D. With Labeled, the label text is outside the graphics, is not rasterized, but is rendered normally.

$\endgroup$
3
  • $\begingroup$ I would have accepted already except that I am unsure that Plot3D rasterises. I have used Rasterize on Plot3D and there is a clear effect as ImageResolution is increased (the plot itself is better, but axes & labels are worse in some respects - no doubt other adjustments are possible but I have not investigated). I will defer to your greater knowledge if you confirm this is in fact the case. $\endgroup$ May 2, 2021 at 14:51
  • $\begingroup$ @JulianMoore What I can say is that zooming in on the PDF from Export clearly shows rasterization (on my Mac) in the one case (i.stack.imgur.com/1QvRv.jpg), and vector (font) graphics in the other. I don't know how the graphics are rasterized when converting to PDF. It's not by a call to Rasterize per Trace. They may use the same underlying function or perhaps a different converter for PDF. I've noticed a difference in axes before, but I don't know why. The graphics are generated in the kernel, axes in the front end; both are displayed by the FE. Significant? I don't know. $\endgroup$
    – Michael E2
    May 2, 2021 at 16:41
  • $\begingroup$ In the front end the Plot3D axes are awful really, and there's no excuse: the text is not rotated and the labelled and unlabelled parts of the box are different thicknesses. However, these comments will serve to highlight the general nature of the problem for anyone else so - accepted! Thanks $\endgroup$ May 2, 2021 at 16:47

Your Answer

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

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