0
$\begingroup$

Consider the following code :

Show[Table[
  Plot[Theta, {Theta, 0, Pi}, PlotLegends -> Style["test", Bold, 20], 
   PlotRange -> All, TicksStyle -> Directive[30], 
   PlotLabel -> 
    Style["zzzzzzzzzzzz zzzzzzzz zzzzzzz zzzzzzzzzzzzzzzz \
zzzzzzzzzzzzz", 22]], {p, {0, 1}}], 
 AxesLabel -> {Style["\[CapitalTheta]", Bold, 20], 
   Style["\[CapitalDelta]E(\[CapitalTheta])", Bold, 20]}]

The result on mathematica, without resizing the screen is :

enter image description here

As you can see the y legends are cut.

And of course when I export it, it is also cut on my image file.

I need to avoid this legend-cutting.

I would like to have an "automatized" way to do it because I have a bunch of graph that I plot and export (so I would like to avoid to manually resizing for example).

I know mathematica love to make simple problems complicated but I would like to avoid having to write 30 lines of code just for this (if it is possible).

$\endgroup$
  • $\begingroup$ It seems to work fine without your incredibly long PlotLabel. Will your plot labels really be that long? If so, you can split it into multiple lines with "zzzzzzzzzz\nzzzzzzzz". Also, your legend doesn't appear to be cut off at all, there's just nothing else to display. $\endgroup$ – MassDefect Jan 17 at 20:34
  • $\begingroup$ @MassDefect here is it a minimal working example I made but my problem is quite similar. On the left you can see I don't have the unit, only the number after the dot ($.5$ instead of $0.5$). Isn't there a simple way to tell to mathematica to write everything I asked him to write (and not cutting things like this ?). Thanks $\endgroup$ – StarBucK Jan 17 at 20:57
  • $\begingroup$ Sorry, I thought you meant the legend on the right side, not the tick mark labels. Yes, I see that the tick labels are cut off. I'll take a stab at an answer. $\endgroup$ – MassDefect Jan 17 at 22:15
1
$\begingroup$

As far as I can tell, the problem is with how wide your title is. It is substantially wider than the graph itself. You can either make the graph wider:

Show[Table[
  Plot[Theta, 
  {Theta, 0, Pi}, 
  PlotLegends -> Style["test", Bold, 20], 
  PlotRange -> All, 
  TicksStyle -> Directive[30],
  ImageSize -> 650,
  PlotLabel -> 
    Style["zzzzzzzzzzzz zzzzzzzz zzzzzzz zzzzzzzzzzzzzzzz \
      zzzzzzzzzzzzz", 22]], {p, {0, 1}}], 
AxesLabel -> {Style["\[CapitalTheta]", Bold, 20], 
   Style["\[CapitalDelta]E(\[CapitalTheta])", Bold, 20]}]

Graph with wide title using ImageSize.

Or you can split the title across multiple lines:

Show[Table[
  Plot[Theta, 
    {Theta, 0, Pi}, 
    PlotLegends -> Style["test", Bold, 20], 
    PlotRange -> All, 
    TicksStyle -> Directive[30],
    PlotLabel -> 
      Style["zzzzzzzzzzzz\nzzzzzzzz\nzzzzzzz\nzzzzzzzzzzzzzzzz\n\
        zzzzzzzzzzzzz", 22]], 
  {p, {0, 1}}], 
  AxesLabel -> {Style["\[CapitalTheta]", Bold, 20], 
       Style["\[CapitalDelta]E(\[CapitalTheta])", Bold, 20]}]

Graph with wide title splitting the title across lines.

Hopefully one of these works for you! If not, you may need to tighten the requirements in your question.

EDIT: You can use the answer from this question if you need to set the ImageSize programmatically.

 t = Text[Style["zzzzzzzzzzzz zzzzzzzz zzzzzzz zzzzzzzzzzzzzzzz \
      zzzzzzzzzzzzz", 20]];
 {w, h} = d = Rasterize[t, "RasterSize"];

The w variable contains the width of the title, so you just set ImageSize -> w for each plot. Since you're making many graphs, I assume they each have different plot labels. Obviously you wouldn't hard code the "zzzzzz zzzzzz...", but instead ask it to find the width of the title for a given plot.

$\endgroup$
  • $\begingroup$ Thank you. But there is thus no option to give to mathematica to let him choose automatically the good ImageSize to have the text that fits in. $\endgroup$ – StarBucK Jan 17 at 22:54
  • 1
    $\begingroup$ @StarBucK I've updated my answer a bit. Hopefully that gets you a bit closer to what you wanted or at least gives you a jumping-off point if you need to design your own code! $\endgroup$ – MassDefect Jan 18 at 1:26
  • $\begingroup$ Thanks ! I will see if some people know other generic way to do it and if not I will validate your answer $\endgroup$ – StarBucK Jan 18 at 9:36

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.