ScottPlot.NET
GitHub Repo stars

Multi-Axis

  • This page contains recipes for the Multi-Axis category.
  • Visit the Cookbook Home Page to view all cookbook recipes.
  • Generated by ScottPlot 4.1.71 on 1/21/2024

Primary Axes

Plots always have 4 fundamental axes available to work with. By default primary axes are totally visible, and secondary axes have ticks hidden and no label. Sometimes the top axis is given a label to simulate a plot title.

This code sample is specific to ScottPlot 4 (details)
ScottPlot.Version.ShouldBe(4, 1, 71);
var plt = new ScottPlot.Plot(600, 400);

// plot one set of data using the primary Y axis
var sigSmall = plt.AddSignal(DataGen.Sin(51, mult: 1), sampleRate: 1);
sigSmall.YAxisIndex = plt.LeftAxis.AxisIndex;
sigSmall.XAxisIndex = plt.BottomAxis.AxisIndex;
plt.BottomAxis.Label("Primary X Axis");
plt.YAxis.Label("Primary Y Axis");
plt.BottomAxis.Color(sigSmall.Color);
plt.YAxis.Color(sigSmall.Color);

// plot another set of data using the secondary axes
var sigBig = plt.AddSignal(DataGen.Cos(51, mult: 100), sampleRate: 100);
sigBig.YAxisIndex = plt.RightAxis.AxisIndex;
sigBig.XAxisIndex = plt.TopAxis.AxisIndex;

// show ticks and labels for axes where they are hidden by default
plt.RightAxis.Ticks(true);
plt.RightAxis.Color(sigBig.Color);
plt.RightAxis.Label("Secondary Y Axis");
plt.TopAxis.Ticks(true);
plt.TopAxis.Color(sigBig.Color);
plt.TopAxis.Label("Secondary X Axis");

plt.SaveFig("multiAxis_primary.png");

Additional Y Axis

Additional axes can be added on any edge. Additional axes stack away from the plot area.

This code sample is specific to ScottPlot 4 (details)
ScottPlot.Version.ShouldBe(4, 1, 71);
var plt = new ScottPlot.Plot(600, 400);

// plot one set of data using the primary Y axis
var sigSmall = plt.AddSignal(DataGen.Sin(51, mult: 1));
sigSmall.YAxisIndex = plt.LeftAxis.AxisIndex;
plt.YAxis.Label("Primary Axis");
plt.YAxis.Color(sigSmall.Color);

// plot another set of data using an additional axis
var sigBig = plt.AddSignal(DataGen.Cos(51, mult: 100));
var yAxis3 = plt.AddAxis(Renderable.Edge.Left);
sigBig.YAxisIndex = yAxis3.AxisIndex;
yAxis3.Label("Additional Axis");
yAxis3.Color(sigBig.Color);

plt.SaveFig("multiAxis_additional.png");

Right Y Axis

This example demonstrates how to display a Y axis on the right side of the figure. The vertical axis to the right of the figure is index 1, so plots must be updated to indicate they are to use a nonstandard axis index.

This code sample is specific to ScottPlot 4 (details)
ScottPlot.Version.ShouldBe(4, 1, 71);
var plt = new ScottPlot.Plot(600, 400);

double[] values = DataGen.RandomWalk(100);
var sig = plt.AddSignal(values);
sig.YAxisIndex = plt.RightAxis.AxisIndex;

plt.YAxis.Ticks(false);
plt.YAxis.Grid(false);
plt.RightAxis.Ticks(true);
plt.RightAxis.Grid(true);
plt.RightAxis.Label("Value");
plt.BottomAxis.Label("Sample Number");

plt.SaveFig("multiAxis_right.png");

Top X Axis

This example demonstrates how to display an X axis above the figure. The horizontal axis above the figure is index 1, so plots must be updated to indicate they are to use a nonstandard axis index.

This code sample is specific to ScottPlot 4 (details)
ScottPlot.Version.ShouldBe(4, 1, 71);
var plt = new ScottPlot.Plot(600, 400);

double[] values = DataGen.RandomWalk(100);
var sig = plt.AddSignal(values);
sig.XAxisIndex = plt.TopAxis.AxisIndex;

plt.BottomAxis.Ticks(false);
plt.BottomAxis.Grid(false);
plt.TopAxis.Ticks(true);
plt.TopAxis.Grid(true);
plt.TopAxis.Label("Sample Number");
plt.YAxis.Label("Value");

plt.SaveFig("multiAxis_top.png");

Axis Visibility

Visibility of axes can be toggled. In this example an additional Y axis is added but the primary Y axis is hidden. The result is a plot that appears to only have one Y axis.

This code sample is specific to ScottPlot 4 (details)
ScottPlot.Version.ShouldBe(4, 1, 71);
var plt = new ScottPlot.Plot(600, 400);

// plot one set of data using the primary Y axis
var sigSmall = plt.AddSignal(DataGen.Sin(51, mult: 1));
sigSmall.YAxisIndex = plt.LeftAxis.AxisIndex;
plt.YAxis.Label("Primary Axis");
plt.YAxis.Color(sigSmall.Color);

// plot another set of data using an additional axis
var sigBig = plt.AddSignal(DataGen.Cos(51, mult: 100));
var yAxis3 = plt.AddAxis(Renderable.Edge.Left);
sigBig.YAxisIndex = yAxis3.AxisIndex;
yAxis3.Label("Additional Axis");
yAxis3.Color(sigBig.Color);

// hide the primary Y axis
plt.YAxis.IsVisible = false;

plt.SaveFig("multiAxis_invisible.png");

Setting Multi Axis Limits

Axis limits can be set for each axis by indicating which axis index you are wish to modify when setting axis limits.

This code sample is specific to ScottPlot 4 (details)
ScottPlot.Version.ShouldBe(4, 1, 71);
var plt = new ScottPlot.Plot(600, 400);

// signal one on the primary Y axis
var sig1 = plt.AddSignal(DataGen.Sin(51, mult: 1));
sig1.YAxisIndex = plt.LeftAxis.AxisIndex;

// signal two on the secondary Y axis
var sig2 = plt.AddSignal(DataGen.Cos(51, mult: 100));
sig2.YAxisIndex = plt.RightAxis.AxisIndex;
plt.RightAxis.Ticks(true);

// set axis limits for each axis individually
plt.SetAxisLimits(yMin: -2, yMax: 2, yAxisIndex: 0);
plt.SetAxisLimits(yMin: -200, yMax: 200, yAxisIndex: 1);

plt.SaveFig("multiAxis_limits.png");