8
$\begingroup$

I have data which I would like to plot along with the corresponding error bars:

{{{54927.7, -1.91044}, 
ErrorBar[38.2664, 0.0538982]}, {{55320.9, -1.97673}, 
ErrorBar[45.3592, 0.101486]}, {{55671.4, -2.15716}, 
ErrorBar[41.2234, 0.0258249]}, {{56032.9, -2.15957}, 
ErrorBar[38.8805, 0.0191277]}, {{56410.6, -2.14289}, 
ErrorBar[41.5501, 0.0189911]}, {{56787.2, -2.19703}, 
ErrorBar[38.1972, 0.00632055]}, {{57137.5, -2.1839}, 
ErrorBar[35.6098, 0.0084108]}, {{57493.3, -2.19994}, 
ErrorBar[38.0298, 0.00651633]}, {{57859.5, -2.19687}, 
ErrorBar[40.9682, 0.00658857]}}

I can use the ErrorListPlot function in mathematica just fine, however if I would like to reverse the y axis scale with the function ScalingFunctions->"Reverse" the error bars do not get plotted along with the data.....any suggestions on how to fix this?

$\endgroup$

1 Answer 1

7
$\begingroup$

You can post-process the ErrorListPlot output to reverse the vertical axis using ReflectionTransform and modify the ticks:

elp = ErrorListPlot[data];
Show[MapAt[GeometricTransformation[#, ReflectionTransform[{0, -1}]] &, elp, {1}], 
 PlotRange -> {1.8, 2.3}, AxesOrigin -> {Automatic, 2.3}, 
 Ticks -> {Automatic, Charting`FindTicks[{0, 1}, {0, -1}] }]

enter image description here

Alternatively,

Show[elp /. p : _Point| _Line :> GeometricTransformation[p, ReflectionTransform[{0, -1}]],
 PlotRange -> {1.8, 2.3}, AxesOrigin -> {Automatic, 2.3}, 
 Ticks -> {Automatic, Charting`FindTicks[{0, 1}, {0, -1}] } ]

same picture

$\endgroup$
2
  • $\begingroup$ This works! Would you be able to explain to me though why the "MapAt" function is needed here and we cannot just use the "GeometricTransformation" function with inputting the ErrorListPlot instead of the "#" ? $\endgroup$
    – msuffak
    Commented Sep 22, 2018 at 23:32
  • 1
    $\begingroup$ @msuffak, You can also do GeometricTransformation[elp[[1]], ReflectionTransform[{0, -1}]] to get the graphics primitives. Then you need to wrap it with Graphics and add the options: Graphics[GeometricTransformation[elp[[1]], ReflectionTransform[{0, -1}]], AspectRatio -> 1/GoldenRatio, Axes -> True, PlotRange -> All, AxesOrigin -> {Automatic, 2.3}, Ticks -> {Automatic, Charting`FindTicks[{0, 1}, {0, -1}]}]. I find MapAt and ReplaceAll just convenient in that the options of elp are retained. $\endgroup$
    – kglr
    Commented Sep 22, 2018 at 23:41

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.