Custom tick labels

Aug 8, 2013 at 6:42 AM
Edited Aug 8, 2013 at 9:21 AM
Hello.
I need to plot some numeric data as a function of audio frequency. The frequency axis (x axis) is in octave bands - which is base 2 log. Here's an example I found online of what I want to plot:
Image
(reference: http://www.dpamicrophones.com/da/MikrofonUniversitet/Tech-Guide/Acoustics.aspx)
The picture is not very good quality, the frequency values are: 63, 125, 250, 500, 1k, 2k, 4k, 8k Hz.

I can't seem to be able to create such an axis. I've tried a few things without success:
  1. Using log axis for frequency - but the values are calculated with a reference of 1. That means values count up as so: 1, 2, 4, 8, 16... etc. I need a way to set a custom reference (e.g. 1000 Hz) so I can start at 63 (or 62.5) and work my way up from there.
  2. Using a category axis for frequency, so I can specify a custom string - but I need the labels to line up with the grid lines, not in between the grid lines (if that makes sense?)
  3. Using a linear axis for frequency - but I see no way of replacing the numeric labels with custom strings.
Does anyone have any ideas? It seems like I need VS2012 (I have 2010) to open and compile the source, so I really am stuck. I think option 1. should be quite easy to implement?
Aug 11, 2013 at 4:59 PM
Edited Aug 11, 2013 at 4:59 PM
You could just override the LogarithmicAxis.GetTickValues() without recompiling oxyplot as I did here.

A hacky, but nonetheless working, example (in VB I'm afraid):
Public Class MyLogAxis
    Inherits Axes.LogarithmicAxis

    Public Overrides Sub GetTickValues(ByRef majorLabelValues As IList(Of Double), ByRef majorTickValues As IList(Of Double), ByRef minorTickValues As IList(Of Double))
        majorTickValues = New List(Of Double)
 
        majorTickValues.Add(63)
        majorTickValues.Add(125)
        majorTickValues.Add(250)
        majorTickValues.Add(500)
        majorTickValues.Add(1000)
        majorTickValues.Add(2000)
        majorTickValues.Add(4000)
        majorTickValues.Add(8000)

        minorTickValues = majorTickValues
        majorLabelValues = majorTickValues

    End Sub
End Class
Aug 13, 2013 at 8:00 AM
Ah, that's awesome. Thank you so much!
Jan 22, 2015 at 12:25 PM
Amazing! Just what I needed!