3
$\begingroup$

I am trying to combine three separated curves into a same figure. The codes are inspired by another post and answers here.

Codes:

snip[pos_] := 
  Arrowheads[{{Automatic, pos, 
     Graphics[{BezierCurve[{{0, -(1/2)}, {1/2, 0}, {-(1/2), 0}, {0, 
          1/2}}]}]}}];

data1 = {{1, 1.1}, {2, 1.5}, {3, 0.9}, {4, 2.3}, {5, 1.1}};
data2 = {{1, 1001.1}, {2, 1001.5}, {3, 1000.9}, {4, 1002.3}, {5, 
    1001.1}};
data3 = {{1, 8001.1}, {2, 8001.5}, {3, 8000.9}, {4, 8002.3}, {5, 
    8001.1}};

getMaxPadding[p_List] := 
 Map[Max, (BorderDimensions@
        Image[Show[#, LabelStyle -> White, Background -> White]] & /@ 
      p)~Flatten~{{3}, {2}}, {2}] + 1

p1 = ListPlot[data1, PlotRange -> All, Joined -> True, Mesh -> Full, 
   PlotStyle -> Red, 
   AxesStyle -> {{Arrowheads[.035], Directive[Black, 12]}, {snip[1], 
      Directive[Black, 12]}}, PlotRangePadding -> .2, 
   ImagePadding -> {{50, 5}, {15, 5}}, AspectRatio -> 1/3];

p2 = ListPlot[data2, PlotRange -> All, Joined -> True, Mesh -> Full, 
   PlotStyle -> Blue, Axes -> {False, True}, 
   AxesStyle -> {{None}, {snip[0], Directive[Black, 12]}}, 
   PlotRangePadding -> .2, ImagePadding -> {{50, 15}, {5, 5}}, 
   AspectRatio -> 1/3];

p3 = ListPlot[data3, PlotRange -> All, Joined -> True, Mesh -> Full, 
   PlotStyle -> Magenta, Axes -> {False, True}, 
   AxesStyle -> {{None}, {snip[0], Directive[Black, 12]}}, 
   PlotRangePadding -> .2, ImagePadding -> {{50, 15}, {5, 5}}, 
   AspectRatio -> 1/3];

output = Column[{p3, p2, p1} /. 
   Graphics[x__] :> 
    Graphics[x, ImagePadding -> getMaxPadding[{p1, p2, p3}], 
     ImageSize -> 500]]
Export["testBrokenAxiesFigure.png", output]

and output are:

enter image description here

  1. How can I add an additional arrow to the vertical axis of the figure?

  2. And how can I change the single Bezier curve separation symbol (at 1002.5 on the vertical axis) into a double Bezier curve symbol like that at about 2.5 on the vertical axis?

$\endgroup$

1 Answer 1

6
$\begingroup$

We have to modify snipa little bit:

ClearAll[snip]

snipCurve = Graphics[
  {BezierCurve[{{0, -(1/2)}, {1/2, 0}, {-(1/2), 0}, {0, 1/2}}]}
];

snip[pos_?NumberQ, primitive_Graphics: snipCurve] :=  snip[
  {pos}, primitive
];

snip[pos_List, primitive_Graphics: snipCurve] := Arrowheads[ 
  {Automatic, #, primitive} & /@ pos
];

snip[pos_List, primitives_List] :=  Arrowheads[
  Flatten /@ MapThread[{Automatic, ##} &, {pos, primitives}]
];

Now it will accept a list of positions as well as list of primitives that should be used. For convenience a default Arrow can be put by {}.

SO, AxesStyle for p2, p3 (p1 without changes) respectively should be:

AxesStyle -> {
  {None}, 
  {snip[{0, 1}], Directive[Black, 12]}
}

AxesStyle -> {
  {None}, 
  {snip[{0, 1}, {snipCurve, {}}], Directive[Black, 12]}
}

enter image description here


Thank you very much! Is it possible to change the size of the vertical axis arrow?

Don't have time to prepare handy and general patterns for snip but we can change something in the last definition:

snip[sizes_List, pos_List, primitives_List] := Arrowheads[
   Flatten /@ Transpose[{sizes, pos, primitives}]
]

Now, let's use this in yspec for p3:

AxesStyle -> {
  {None}, 
  {snip[{Automatic, .1}(*here*), {0, 1}, {snipCurve, {}}], Directive[Black, 12]}
}

and xspec for p1 can be changed directly:

AxesStyle -> {
  {Arrowheads[.1(*here*), .035], Directive[Black, 12]}, 
  {snip[1], Directive[Black, 12]}
}

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you very much! Is it possible to change the size of the vertical axis arrow? ---I noticed there is a package SciDraw for scientific drawing, if such functions here can be generalized and combined into SciDraw, that would be great. $\endgroup$ Commented Apr 18, 2016 at 23:34
  • $\begingroup$ BTW @Kuba, I also noticed in one of your answers, you posted "风向图" as a PlotTitle, are you a native speaker of such language? $\endgroup$ Commented Apr 18, 2016 at 23:39
  • 1
    $\begingroup$ @user6043040 I will try to address your question about size in the incomming edit. No, I'm from the very center of Europe, that probably was the wind rose phrase I've googled to match OPs needs. $\endgroup$
    – Kuba
    Commented Apr 19, 2016 at 6:04

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.