13
$\begingroup$

I am delighted to see the new MultiaxisArrangement feature, but when I tried it, I could not figure out how to label the two axes. For example, the following produces no axis labels. Nor does any configuration of AxesLabel or FrameLabel that I have tried.

ListLinePlot[{{1, 2, 3}, 10 {3, 2, 1}}
, MultiaxisArrangement -> All
, FrameLabel -> {{"A", "B"}, {"C", "D"}}]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ The InputForm of that plot does not look right. Seems like a bug to me. You should report it to Wolfram Support. $\endgroup$ Jan 1 at 0:39
  • 3
    $\begingroup$ yet another bug when MultiaxisArrangement is used: PlotLegends is ignored. $\endgroup$
    – kglr
    Jan 1 at 13:52
7
$\begingroup$

For a workaround use Labeled

Clear["Global`*"]

Labeled[
 ListLinePlot[
  {{1, 2, 3}, 10 {3, 2, 1}},
  MultiaxisArrangement -> All],
 {"bottom", Rotate["left", Pi/2],
  "top", Rotate["right", Pi/2]}, All]

enter image description here

EDIT: Or more simply,

Labeled[
 ListLinePlot[
  {{1, 2, 3}, 10 {3, 2, 1}},
  MultiaxisArrangement -> All],
 {"bottom", "left", "top", "right"}, All,
 RotateLabel -> True]

(* same picture *)

$\endgroup$
3
$\begingroup$

Another work-around: Add the frame labels using Show.

addFrameLabels adds desired frame labels using an invisible frame and ticks to adjust the positioning of labels:

ClearAll[addFrameLabels]
addFrameLabels[gap_ : .01] := Show[#, FrameLabel -> #2, Frame -> True, 
    FrameTicks -> {{#, #} & @ {{.5, Invisible["m"], {0, gap}}}, 
         {{{.5, Invisible["m"], {0, gap/10}}}, None}}, 
    FrameStyle -> StrokeForm[Opacity[0]],  PlotRangePadding -> 0] &;

Examples:

addFrameLabels[][ListLinePlot[{{1, 2, 3}, 10 {3, 2, 1}}, 
    MultiaxisArrangement -> All, ImageSize -> 500], 
  {{"A", "B"}, { "C", "D"}}] 

enter image description here

addFrameLabels[.07][ListLinePlot[{10000 {1, 2, 3}, 10 10000 {3, 2, 1}}, 
      MultiaxisArrangement -> All, ImageSize -> 500], 
  {{"A", "B"}, { "C", "D"}}]

enter image description here

$\endgroup$
1
  • $\begingroup$ this works only for two multi-axes. $\endgroup$
    – kglr
    Jan 1 at 14:27
3
$\begingroup$

A work-around that works with arbitrary number of axes: post-process to inject the option AxisLabel to AxisObjects:

ClearAll[fixMultiAxisLabels]
fixMultiAxisLabels[off_ : 1.5, opts : OptionsPattern[]] := 
  Module[{al = #2}, 
    ReplaceAll[Offset[o : Except[0, _], z_] :> Offset[off  o, z]]@*
      ReplaceAll[AxisObject[a_, b_, c___] :> 
        AxisObject[a, b, Last[al = RotateLeft[al]], opts, c]]@#] &;

Examples:

llp = ListLinePlot[{{1, 2, 3}, 10 {3, 2, 1}}, 
    MultiaxisArrangement -> All, ImageSize -> 500];

labels = {"A", "B", "C", "D"};

axislabels = Thread[AxisLabel -> Placed @@@
Transpose[{labels, {0.5, {0.5, #}}&/@ {-2.5, 2.5, 2.5, -.5}}]]

fixMultiAxisLabels[][llp, axislabels] 

enter image description here

llp2 = ListLinePlot[{10000 {1, 2, 3}, 10 10000 {3, 2, 1}}, 
     MultiaxisArrangement -> All, ImageSize -> 500, LabelStyle -> 16];

axislabels2 = Thread[AxisLabel -> Placed @@@ 
    Transpose[{labels, {0.5, {0.5, #}} & /@ {-3.5, 5, 2.5, -.5}}]]

fixMultiAxisLabels[][llp2, axislabels2] 

enter image description here

An example with 4 vertical axes:

llp3 = ListLinePlot[{{1, 2, 3}, 10 {3, 2, 1}, 500 {2, 1, 3}, 1000 {1, 3, 2}}, 
   MultiaxisArrangement -> All, ImageSize -> 800];

labels3 = {"left 1", "left 2", "right 1", "right 2", "bottom", "top"};

axislabels3 = Thread[AxisLabel -> Placed @@@ 
   Transpose[{labels3, {0.5, {0.5, #}} & /@ {-2, -1.25, 3.25, 4,  2.5, -.5} }]];

fixMultiAxisLabels[2, LabelStyle -> 14][llp3, axislabels3] 

enter image description here

$\endgroup$

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.