1

I'm currently using AndroidPlot to display a dynamic XY plot. The Python script that usually displays this data also includes the ability to graph data with a logarithmic scale using Matplotlib. Is it possible to have a logarithmic Y-axis using AndroidPlot, or even any kind of y-axis with ticks that are not equally spaced value-wise?

Thank you for your help.

Lillian H
  • 33
  • 5

1 Answers1

2

You can definitely do this with Androidplot, however it's not as simple as setting a config param.

The easiest approach is probably to extend an implementation of XYSeries and adjust the getY(int) method to return a log value instead of the raw value. For example to implement log10 on the y-axis only:

class LogXYSeries extends SimpleXYSeries {

        public LogXYSeries(String title) {
            super(title);
        }

        @Override
        public Number getY(int index) {
            final Number rawY = super.getY(index);
            if(rawY != null) {
                Math.log10(rawY.doubleValue());
            }
            return null;
        }
}

As far as ticks go, you can configure those to appear by a fixed value increment or as an even subdivision of the visible range of values (default is to fit min/max in your series data, but you can manually set this if you prefer.) . I'd imagine subdividing would be what you're looking for with a log scale.

If I misunderstood what you're trying to accomplish and you just want to apply the log scale to the tick labels you can do that too. There's an example of setting a custom formatter in the Domain & Range Labels documentation for XYPlots.

Nick
  • 8,181
  • 4
  • 38
  • 63
  • I am aiming to apply the log scale to the ticks. I may be mistaken, but wouldn't setting a custom formatter only change the appearance of the tick labels and not their actual values? In any case, this has been really helpful! Thank you. – Lillian H Aug 07 '17 at 14:35
  • That is correct. They would still be accurate in terms of labeling but the plotted data would look different because the log scaling wouldn't be applied. The LogXYSeries approach is what you're probably after but I thought I'd mention how to just print labels as log values just in case. – Nick Aug 08 '17 at 12:58