Group Abstract Group Abstract

Message Boards Message Boards

0
|
22 Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

Automatically scale labels based on image size

Posted 14 hours ago

Jupyter screenshot for the following Mathematica code is shown alongside python analogue. The latter scales axes' labels and plot thickness, not the former: is there a Plot[] option for that?

SetOptions[Plot,
  Background -> GrayLevel[0.95],
  AxesStyle -> Black,
  LabelStyle -> Black
];

Plot[Sin[x], {x, 0, 10},ImageSize->100]

jupyter screenshot

P.S. : The reason for SetOptions is the default background is black. Is that a new thing?

POSTED BY: Erwann Rogard
3 Replies
Posted 9 hours ago

It was a wrong assumption of mine that matplotlib automatically scales labels' size and thickness. Here's additional insight about specified/actual image size, and evidence of "background is black". This is all after restarting the kernel:

g=Plot[
  Sin[x],
  {x, 0, 10},
  ImageSize -> 100,
  TicksStyle -> Scaled[.005],
  PlotStyle  -> Thickness[.01]
];
{ImageDimensions[g],ImageSize /. Options[g]}

Show[g]

jupyter screenshot

POSTED BY: Erwann Rogard
Posted 9 hours ago

On my system, the background of the plot is not black. It's white or transparent, as far as I can tell.

As for the "specified/actual image size", is this a new issue, or did I misunderstand your original question? It doesn't matter, I'm just now wondering if I went down the wrong road in trying to respond. Anyway, it is very tricky getting pixel-perfect accuracy when trying to treat plots as images. This would lead to a very long and complicated conversation, so, before I go down that road, I'd rather you explain what your objective is, what level of quality you'd be satisfied with, and whatever unstated requirements might be relevant. Although, having said that, I probably can't help all that much since I don't use Jupyter, and clearly that environment works differently than my plain MMA.

POSTED BY: Eric Rimbey
Posted 13 hours ago

Caveat: I don't use Jupyter, so I don't know if there is anything about that environment that is relevant to your question. I'm using a Mac and running MMA version 14.3.

Taking your questions in reverse order:

default background is black. Is that a new thing?

I don't know what you're referring to exactly, but I don't see black backgrounds in my plots and the Plot options do not show anything defaulting to black. Specifically, the default for Background is None. Maybe Jupyter somehow displays None as black?

The latter scales axes' labels and plot thickness, not the former: is there a Plot[] option for that?

You can use PlotStyle to adjust the thickness of the line. You can use TickStyle to set FontSize. For example,

Plot[Sin[x], {x, 0, 10}, TicksStyle -> FontSize -> Scaled[.05], PlotStyle -> Thickness[.05]]

But I think you might run into problems using an image size so small. Also, the image you show looks like the image of the plot was actually resized to be larger than 100 after the plot was created, which would explain why the font and line seem large. Maybe that's another Jupyter thing, IDK.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard