1
$\begingroup$

I have the following vector:

t0={1.0023, 1.0023, 1.0023, 1.0023, 0.88191, 0.88191, 0.6682, 0.6682, \
1.25614, 1.25614, -1.20461, -1.20461, -1.20461, -1.20461, -1.05992, \
-1.05992}

and I'm trying to build a ListStepPlot with two y-axes, such that the last six negative values can be plotted in the top part of the diagram. Here is my code:

d=30;line = Line[{{11, 0}, {11, .32}}]; plot1 = 
ListStepPlot[Normalize@t0, 
PlotRange -> {{0.95, 16.5}, {0.15, 0.32}}, 
ImageSize -> Large, ImagePadding -> d, 
Epilog -> {Directive[Black, Thick, Dashed], line}]; plot2 = 
ListStepPlot[Normalize@t0, PlotRange -> {{0.95, 16.5}, {-0.32, 0}}, 
ImageSize -> Large, ImagePadding -> d, Axes -> False, 
Frame -> {False, False, False, True}, 
FrameTicks -> {{None, All}, {None, None}}]; Overlay[{plot1, plot2}]

I would like the plot 2 should be "reflected", that is, the origin of the right y-axes should be at the same level as that of the left y-axes.

How can I do this?

$\endgroup$
3
$\begingroup$

You can get the desired result in a single ListStepPlot using Abs @ Normalize @ t0 as input and and using Charting`ScaledTicks["Reverse"] to reverse the tick labels on the right axis:

ListStepPlot[
     Abs @ Normalize @ t0, 
     PlotRange -> All,
     ImageSize -> Large, 
     Epilog -> {Directive[Black, Thick, Dashed], line},
     Frame -> {{True, True}, {True, False}},
     FrameTicks -> {{Automatic, Charting`ScaledTicks["Reverse"]}, {Automatic, None}},
     FrameLabel -> {Style[#, 16] &/@ {t, t}, {Style[e, 16], None}}
   ]

enter image description here

Note: You can also use Charting`FindTicks[- {0, 1}, {0, 1}] instead of Charting`ScaledTicks["Reverse"], and

GridLines -> {{{11,Directive[Opacity[1],Black, Thick, Dashed]}}, None}

instead of Epilog -> ... to get the same picture.

$\endgroup$
  • $\begingroup$ how can I add the labels? $\endgroup$ – Gae P Jul 16 at 16:10
  • 1
    $\begingroup$ @GaeP, please see the updated version. $\endgroup$ – kglr Jul 16 at 16:14
  • $\begingroup$ Thanks! another question: I would like to use PlotLegends -> PointLegend["t", LegendMarkers -> Automatic] but it seems doesn't work with ListStepPlot... $\endgroup$ – Gae P Jul 17 at 9:21
  • 1
    $\begingroup$ @GaeP, try PointLegend[ {"t"}, LegendMarkers->{Automatic}] or LineLegend[ {"t"}, LegendMarkers->{Automatic}] $\endgroup$ – kglr Jul 17 at 9:46
1
$\begingroup$

I'm not sure if I'm understanding what you want to do, exactly. Is this what you're looking for?

Plot with right axis reversed.

If so, this is the code I used:

t0 = {1.0023, 1.0023, 1.0023, 1.0023, 0.88191, 0.88191, 0.6682, 
  0.6682, 1.25614, 
  1.25614, -1.20461, -1.20461, -1.20461, -1.20461, -1.05992, \
-1.05992}
d = 30; 
line = Line[{{11, 0}, {11, .32}}]; 
plot1 = ListStepPlot[
    Normalize@t0, 
    PlotRange -> {{0.95, 16.5}, {0.15, 0.32}},
    ImageSize -> Large, 
    ImagePadding -> d, 
    Epilog -> {Directive[Black, Thick, Dashed], line}
  ]; 
plot2 = ListStepPlot[
     Normalize@t0, 
     PlotRange -> {{0.95, 16.5}, {-0.32, -0.15}}, 
     ImageSize -> Large, 
     ImagePadding -> d, 
     Axes -> False, 
     Frame -> {False, False, False, True}, 
     FrameTicks -> {{None, All}, {None, None}}, 
     ScalingFunctions -> {None, "Reverse"}
   ]; 
Overlay[{plot1, plot2}]

The only things I changed were the PlotRange in plot2 and I added ScalingFunctions -> {None, "Reverse"} to plot2.

$\endgroup$
  • $\begingroup$ Further requests: if I add in plot1 AxesLabel -> {"e","t"}, the x-axes' label overlaps to the ticks of the right y-axes. Moreover, I would like AxesLabel -> { ,"t"} at plot2. How can I do? $\endgroup$ – Gae P Jul 16 at 15:28

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.