ScottPlot.NET
GitHub Repo stars

Tooltip

Tooltip Quickstart

Tooltips are annotations that point to an X/Y coordinate on the plot.

ScottPlot.Plot myPlot = new();

double[] ys = Generate.Sin(50);
var plt = myPlot.Add.Signal(ys);
plt.MaximumMarkerSize = 20;

Coordinates tip = new(25, ys[25]);
Coordinates label = tip.WithDelta(8, .7);
myPlot.Add.Tooltip(tip, "Special Point", label);

myPlot.SavePng("demo.png", 400, 300);

Tooltip Label Styling

Tooltips fonts can be customized.

ScottPlot.Plot myPlot = new();

double[] ys = Generate.Sin(50);
var plt = myPlot.Add.Signal(ys);
plt.MaximumMarkerSize = 20;

Coordinates tip = new(25, ys[25]);
Coordinates label = tip.WithDelta(8, .7);
var tooltip = myPlot.Add.Tooltip(tip, "Hello", label);
tooltip.LabelFontName = "Comic Sans MS";
tooltip.LabelFontSize = 36;
tooltip.LabelBold = true;

myPlot.SavePng("demo.png", 400, 300);

Tooltip Colors

Tooltips border and fill styles can be customized.

ScottPlot.Plot myPlot = new();

double[] ys = Generate.Sin(50);
var plt = myPlot.Add.Signal(ys);
plt.MaximumMarkerSize = 20;

Coordinates tip = new(25, ys[25]);
Coordinates label = tip.WithDelta(8, .7);
var tooltip = myPlot.Add.Tooltip(tip, "Special Point", label);
tooltip.FillColor = Colors.Blue;
tooltip.LineColor = Colors.Navy;
tooltip.LineWidth = 3;
tooltip.LabelFontColor = Colors.Yellow;

myPlot.SavePng("demo.png", 400, 300);

Tooltip Tail Width

Customizable tooltip tail width percentage. The actual width of the tail is the lesser of the length or width of the tooltip body.

ScottPlot.Plot myPlot = new();

double[] widthFraction = [0.3, 0.5, 0.7, 1.0];

for (int i = 0; i < widthFraction.Length; i++)
{

    Coordinates tip = new(0, i * 2);
    Coordinates label = tip.WithDelta(2, 1);
    var tooltip = myPlot.Add.Tooltip(tip, $"Width={widthFraction[i]}", label);
    tooltip.TailWidthPercentage = widthFraction[i];
}

myPlot.Axes.SetLimits(-3, 7, -1, 9);

myPlot.SavePng("demo.png", 400, 300);

Tooltip Angle

The shape of tooltips automatically adjusts according to the position of the tip relative to the label.

ScottPlot.Plot myPlot = new();

for (int i = 0; i < 360; i += 30)
{
    Coordinates tip = new(0, 0);
    PolarCoordinates polar = new(1, Angle.FromDegrees(i));
    Coordinates label = polar.ToCartesian();
    var tooltip = myPlot.Add.Tooltip(tip, $"{i}º", label);
    tooltip.FillColor = Colormap.Default.GetColor(i, 360).Lighten(0.5);
    tooltip.LineColor = Colormap.Default.GetColor(i, 360);
    tooltip.LineWidth = 2;
    tooltip.LabelBold = true;
    tooltip.LabelFontColor = Colormap.Default.GetColor(i, 360).Darken(0.5);
}

myPlot.Axes.SetLimits(-1.5, 1.5, -1.5, 1.5);

myPlot.SavePng("demo.png", 400, 300);