杂项
 

样条插值

插值样条曲线创建具有多个X/Y点的曲线,以平滑连接有限数量的输入点。

var plt = new ScottPlot.Plot(600, 400);

// create a small number of X/Y data points and display them
Random rand = new(1234);
double[] xs = DataGen.RandomWalk(rand, 20);
double[] ys = DataGen.RandomWalk(rand, 20);

// interpolate the data to create a smooth curve
(double[] smoothXs, double[] smoothYs) = ScottPlot.Statistics.Interpolation.Cubic.InterpolateXY(xs, ys, 200);

// plot the original vs interpolated lines
plt.AddScatter(xs, ys, Color.Green, markerSize: 10, lineWidth: 1, label: "Original");
plt.AddScatter(smoothXs, smoothYs, Color.Magenta, label: "Interpolated");
plt.Legend();

plt.SaveFig("misc_interpolation.png");
 

样条插值类型

使用插值、曲线拟合或切角来平滑数据有不同的方法。请注意,有些方法会生成穿过原始数据点的曲线,而有些方法则不会。

var plt = new ScottPlot.Plot(600, 400);

plt.Palette = ScottPlot.Palette.ColorblindFriendly;

// generate random data
System.Random rand = new(12345);
var xs = ScottPlot.DataGen.RandomWalk(rand, 20);
var ys = ScottPlot.DataGen.RandomWalk(rand, 20);
plt.AddScatter(xs, ys, lineStyle: ScottPlot.LineStyle.Dash, markerSize: 10, label: "original");

// interpolate the same data in different ways
(double[] bzX, double[] bzY) = ScottPlot.Statistics.Interpolation.Bezier.InterpolateXY(xs, ys, .005);
(double[] crX, double[] crY) = ScottPlot.Statistics.Interpolation.CatmullRom.InterpolateXY(xs, ys, 15);
(double[] chX, double[] chY) = ScottPlot.Statistics.Interpolation.Chaikin.InterpolateXY(xs, ys, 4);
(double[] cbX, double[] cbY) = ScottPlot.Statistics.Interpolation.Cubic.InterpolateXY(xs, ys, 200);

// display the different curves as line plots
plt.AddScatterLines(bzX, bzY, lineWidth: 2, label: $"Bezier");
plt.AddScatterLines(crX, crY, lineWidth: 2, label: $"Catmull-Rom");
plt.AddScatterLines(chX, chY, lineWidth: 2, label: $"Chaikin");
plt.AddScatterLines(cbX, cbY, lineWidth: 2, label: $"Cubic");

// style the plot
plt.Legend();
plt.Frameless();
plt.Grid(false);
plt.XAxis2.Label("Spline Interpolation", size: 28, bold: true);

plt.SaveFig("misc_interpolation_types.png");
 

动作电位

哺乳动物动作电位的原始轨迹(电压)和一阶导数(电压变化/时间)。

var plt = new ScottPlot.Plot(600, 400);

// obtain a signal for the voltage
double[] ap = DataGen.ActionPotential();
plt.Title("Neuronal Action Potential");

// data is sampled at 20 kHz but we want to display ms units
int sampleRate = 20;
plt.XAxis.Label("Time (milliseconds)");

// plot the voltage in blue on the primary Y axis
var sig1 = plt.AddSignal(ap, sampleRate);
sig1.YAxisIndex = 0;
sig1.LineWidth = 3;
sig1.Color = Color.Blue;
plt.YAxis.Label("Membrane Potential (mV)");
plt.YAxis.Color(Color.Blue);

// calculate the first derivative
double[] deriv = new double[ap.Length];
for (int i = 1; i < deriv.Length; i++)
    deriv[i] = (ap[i] - ap[i - 1]) * sampleRate;
deriv[0] = deriv[1];

// plot the first derivative in red on the secondary Y axis
var sig2 = plt.AddSignal(deriv, sampleRate);
sig2.YAxisIndex = 1;
sig2.LineWidth = 3;
sig2.Color = Color.FromArgb(120, Color.Red);
plt.YAxis2.Label("Rate of Change (mV/ms)");
plt.YAxis2.Color(Color.Red);
plt.YAxis2.Ticks(true);

// zoom in on the interesting area
plt.SetAxisLimits(40, 60);

plt.SaveFig("misc_ap.png");
 

显示缩放

当显示缩放功能启用时,每英寸点数(DPI)会发生变化,因此图像看起来更大。当缩放比例增加时,位图图像会被拉伸,看起来更大,但可能会因此变得模糊。或者,当启用DPI缩放功能时,图像的大小可以增加,但字体和线条可能看起来很小。本例显示了如何增加公共绘图组件的大小,使其在高分辨率缩放显示器(例如4K显示器)上看起来良好。DPI拉伸可以在用户控件的配置模块中设置。

var plt = new ScottPlot.Plot(600, 400);

var sig1 = plt.AddSignal(DataGen.Sin(51));
sig1.Label = "Sin";
sig1.MarkerSize = 7;
sig1.LineWidth = 2;

var sig2 = plt.AddSignal(DataGen.Cos(51));
sig2.Label = "Cos";
sig2.MarkerSize = 7;
sig2.LineWidth = 2;

var legend = plt.Legend();
legend.FontSize = 24;

plt.Title("Plot with Large Features");
plt.YLabel("Vertical Axis");
plt.XLabel("Horizontal Axis");

plt.YAxis.LabelStyle(fontSize: 24);
plt.XAxis.LabelStyle(fontSize: 24);
plt.XAxis2.LabelStyle(fontSize: 36);

plt.YAxis.TickLabelStyle(fontSize: 18);
plt.XAxis.TickLabelStyle(fontSize: 18);

plt.YAxis.MajorGrid(lineWidth: 2);
plt.XAxis.MajorGrid(lineWidth: 2);

plt.SaveFig("misc_dpiScale.png");