Question

Project demonstrating the problem here: http://github.com/danieljfarrell/CorePlotBoxAxis


I want make a plot like the following where the we have a "box" axis, i.e. that axes are always on the outer edge of the plot area.

Plot

Here x and y axes are the bottom and left edges; x2 and y2 are the top and right edges, respectively.

In the past I have done with by setting the orthogonalCoordinateDecimal of the axis. However, this requires updating the coordinate manually when the plot ranges change.

Is it possible to implement the box axis with constraints system? I have tried the following and it correctly pins x,y. However, x2 is not visible (presumably it is being pinned somewhere outside of the range) and y2 has a 1 pixel offset (see below).

I have tried a few variations on the y2 constraint but nothing seems to help.

    CPTXYAxis *x = [self _makeDefaultAxis];
    x.coordinate = CPTCoordinateX;
    x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
    x.tickDirection = CPTSignPositive;
    // ...

    CPTXYAxis *y = [self _makeDefaultAxis];
    y.coordinate = CPTCoordinateY;
    y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
    y.tickDirection = CPTSignPositive;
    // ...

    CPTXYAxis *y2 = [self _makeDefaultAxis];
    y2.coordinate = CPTCoordinateY;
    y2.axisConstraints = [CPTConstraints constraintWithUpperOffset:0.0];
    y2.tickDirection = CPTSignNegative;
    // ...

    // Problem here ...
    CPTXYAxis *x2 = [self _makeDefaultAxis];
    x2.coordinate = CPTCoordinateX;
    y2.axisConstraints = [CPTConstraints constraintWithUpperOffset:0.0];
    x2.tickDirection = CPTSignNegative;

This code generates the following plot. Any ideas on how to mirror an axis in this way?

Coreplot

Was it helpful?

Solution

There's a typo in the x2 setup section. Change

y2.axisConstraints = …

to

x2.axisConstraints = …
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top