3
$\begingroup$

I finally installed 13.3 coming from 12.3 and I was giving some new features a test. I was excited by the new PlotLayout feature of Plot that generates grids of plots sharing axes. However, I ran into trouble trying to control the appearance of the frame ticks when compared to the standard overlaid presentation:

f = Plot[
      {Sin[x], Sin[2 x] - 1/2, Cos[x], Sin[x]^2}, {x, -2 Pi, 2 Pi},
      Frame -> True, Axes -> False,
      FrameTicks -> {{Automatic, None}, {Range[-2 Pi, 2 Pi, Pi], None}}
      PlotLayout -> #
    ] &;

f /@ {"Row", Automatic}

four plots, with clipped ticks at top and non-symbolic ticks at bottom the same four plots, but overlaid in a single panel

The bottom is what I would have expected: the horizontal frame ticks are symbolic multiples of $\pi$, and no ticks are produced at the bottom and on the right of the plot.

The top figure, stemming from the "Row" arrangement, was surprising to me: I didn't get the symbolic ticks at the bottom, there are unexpected ticks at the top that are partially clipped, there are clipped ticks on the right as well... In short, a rather poor presentation.

  • How do I get symbolic ticks in a multipanel plot?
  • How do I achieve control of which ticks are shown on which axes?
  • I understand the choice of making all plots the same color in the Row presentation but, if needed, could I have the grid of plots automatically styled in the default colors, as used in the standard overlaid presentation?
$\endgroup$
1
  • 4
    $\begingroup$ From what I can tell, the PlotLayout functionality offers very limited (if any) per-panel control over the various settings (although this is rather a case of not even a common setting working). If you really want the extra level of control, I'd suggest you to take a look at ResourceFunction["PlotGrid"] - while less automatic, you can simply style each panel as you want before combining them (with many options for fine-tuning the result) $\endgroup$
    – Lukas Lang
    Commented Jul 7, 2023 at 23:54

1 Answer 1

3
$\begingroup$

As Lukas Lang noted in comments ResourceFunction["PlotGrid"] is a much more convenient alternative to PlotLayout.

A work-around to get the desired results using PlotLayout:

  1. Wrap input functions with desired styles using Style.
  2. Specify ticks as a list of $\{value, label\}$ pairs.
  3. Use FrameTicksStyle to make unwanted ticks invisible.

funcs = {Sin[x], Sin[2 x] - 1/2, Cos[x], Sin[x]^2};

colors = ColorData["Rainbow"] /@ Rescale[Range[Length @ funcs]];

styledfuncs = MapThread[Style] @ {funcs, colors};

ft = {{Automatic, None},
  {Transpose[{#, ToString[#, TraditionalForm] & /@ #}] & @ 
   Range[-2 π, 2 π, π], None}};


f2 = Plot[Evaluate @ styledfuncs,
    {x, -2 π, 2 π},
    ##2,
    PlotLegends -> "Expressions",
    Axes -> False,
    Frame -> True,
    FrameTicks -> ft,
    FrameTicksStyle -> {{Automatic, Opacity[0]}, {Automatic, Opacity[0]}},
    PlotLayout -> #] &;

Grid[List /@ 
  {f2["Row", ImageSize -> 1 -> 70, Method -> {"Spacings" -> {16, 1}}],
   f2[Automatic, ImageSize -> 1 -> 60]}]

enter image description here

Grid[List @ 
   {f2["Column", ImageSize -> 1 -> 70,
      PlotLegends -> None, Method -> {"Spacings" -> {5, 5}}],
    f2[Automatic, ImageSize -> 1 -> 60]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Excellent as usual. Thank you! $\endgroup$
    – MarcoB
    Commented Jul 10, 2023 at 14:06

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.