Skip to content

Axis: TickLabelFormat accepts Func<double, string>#1100

Merged
swharden merged 1 commit intomasterfrom
1070-label-function
May 30, 2021
Merged

Axis: TickLabelFormat accepts Func<double, string>#1100
swharden merged 1 commit intomasterfrom
1070-label-function

Conversation

@swharden
Copy link
Member

This PR adds an option for the user to use a Func<double, string> to define how to generate tick labels from positions.

Unlike current methods which only control the format of labels or require the user to interact with a complex inheritance system, this is a quick and simple way to control tick label format in a way that uses logic.

plt.AddSignal(ScottPlot.DataGen.Sin(51));
plt.AddSignal(ScottPlot.DataGen.Cos(51));

static string customTickFormatter(double position)
{
    if (position == 0)
        return "zero";
    else if (position > 0)
        return $"+{position:F2}";
    else
        return $"({Math.Abs(position):F2})";
}

plt.XAxis.TickLabelFormat(customTickFormatter);
plt.YAxis.TickLabelFormat(customTickFormatter);

image

This PR was motivated by #926 and #1070

@swharden swharden linked an issue May 30, 2021 that may be closed by this pull request
@swharden swharden merged commit 8d516f7 into master May 30, 2021
@swharden swharden deleted the 1070-label-function branch May 30, 2021 21:14
@danhi
Copy link

danhi commented Oct 14, 2024

my Plot object doesn't have and xaxis item. It has axes, axes.bottom, but they wont take the customtickformater. I'm sure I'm missing something simple here. i'm using VB.Net and the latest version of scottplot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for a custom tick label formatting function

2 participants