2
votes

I would like to use core-plot to display a water depth graph (updated in real time) but I can't figure out how to reverse the Y axis, so that the X axis (representing the time domain) is on the top of my UIView and the Y axis grows towards the bottom with positive values.

EDIT

It would be even better if I could draw axes like this:
- X axis is time
- Y axis is from 0 to X (X > 0) and on the top there is 0, on the bottom there is X
- X axis is on the bottom

ASCII version:

0 |
1 |
.
.
.
x |
--------------------------

0 1 2 3 4 5 6 7 ...

2

2 Answers

1
votes

You can use a negative length for the plot range to reverse the direction of an axis. For example (from the axis demo in CPTTestApp):

plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0)
                                                length:CPTDecimalFromDouble(-10.0)];
0
votes

This ended up being a bit tricky to understand from the accepted answer. To add another example for anyone having issues understanding how to flip the y axis values in coreplot, you really need to declare the plotRangeWithLocation to be the positive number you want to achieve, then set the length to the same negative number like this:

plotSpacePressureLeft.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(9000)
 length:CPTDecimalFromFloat(-9000)];

This produces a y-axis like this as of iOS 14 and coreplot mid 2020 versions:

This produces a y-axis like this