ScottPlot 4.0使用手册

⚠️ 警告:这本使用手册已经过时了。本文档页于2020年12月12日专门为ScottPlot 4.0.47生成。 参观ScottPlot使用手册页面获取最新版本使用手册的链接。

目录

  快速入门
    快速启动:快速启动-散点图快速启动
    快速入门:快速入门-500万分
  打印类型
    打印类型:注释-注释快速启动
    打印类型:箭头-打印箭头
    打印类型:AxisLine-AxisLine快速启动
    打印类型:轴线-可拖动轴线
    打印类型:AxisSpan-Axis Span快速启动
    绘图类型:AxisSpan-可拖动的轴跨距
    打印类型:条形-条形打印快速启动
    绘图类型:条形图-分组条形图
    PlotTypes:条形图
    绘图类型:条形图-水平条形图
    绘图类型:条形图-堆叠条形图
    绘图类型:条形图-显示条形图上方的值
    绘图类型:条形图-瀑布图
    打印类型:Colormap-Colormap快速启动
    PlotTypes:ErrorBar-带有不对称ErrorBar的散点图
    绘图类型:填充-填充曲线
    绘图类型:填充-曲线之间的填充
    打印类型:上方填充和下方填充
    打印类型:填充-使用基线在上方和下方填充
    绘图类型:财务-财务OHLC图表
    绘图类型:财务-财务烛台图
    情节类型:财务-有缺口的OHLC
    情节类型:财务-无空白OHLC
    绘图类型:金融-简单移动平均线(SMA)
    情节类型:金融-布林格乐队
    绘图类型:函数-函数绘图
    打印类型:图像-图像快速启动
    打印类型:图像-图像对齐
    绘图类型:饼图-快速启动
    绘图类型:饼图-分解饼图
    绘图类型:饼图-甜甜圈绘图
    绘图类型:饼图-带文本的圆环图
    绘图类型:饼图-显示值
    绘图类型:饼图-显示百分比
    PlotTypes:饼图-在切片中显示标签
    绘图类型:图例中的饼图标签
    绘图类型:饼图-显示所有内容
    打印类型:饼图-自定义切片标签
    打印类型:点-打印点
    打印类型:多边形-多边形快速启动
    PlotTypes:多边形填充线打印
    PlotTypes:多边形填充的线图
    PlotTypes:多边形-使用多个多边形打印多边形
    PlotTypes:多边形-使用多个多边形打印多边形
    PlotTypes:总体-绘制总体
    绘图类型:总体-统一总体系列
    绘图类型:总体-唯一总体系列
    绘图类型:总体-绘制总体多系列
    打印类型:总体-高级样式
    绘图类型:雷达-快速启动
    绘图类型:雷达-带标签的雷达
    绘图类型:比例尺-比例尺
    绘图类型:散点-散点图快速启动
    打印类型:散布-自定义标记
    打印类型:散布-所有标记形状
    打印类型:散布-自定义线
    绘图类型:散布-随机X/Y点
    绘图类型:散点-带有错误条的散点图
    PlotTypes:散点-保存散点图数据
    PlotTypes:ScatterHighlight-高亮显示散点图快速启动
    绘图类型:信号-信号绘图快速启动
    PlotTypes:信号样式的信号图
    绘图类型:信号-500万点
    PlotTypes:信号-保存信号打印数据
    绘图类型:信号-显示数据密度
    绘图类型:信号-显示前N个点
    绘图类型:信号-绘制一系列点
    绘图类型:信号-填充如下
    绘图类型:信号-下方的渐变填充
    绘图类型:信号-上面的渐变填充
    绘图类型:信号-上下填充
    绘图类型:信号-上下渐变填充
    绘图类型:SignalConst-500万点
    绘图类型:SignalConst-上下渐变填充
    绘图类型:SignalXY-带有X和Y数据的信号
    打印类型:SignalXY-大间隙
    打印类型:SignalXY-不同密度
    绘图类型:SignalXYConst-带有X和Y数据的SignalConst
    PlotTypes:SignalXYConst-xs和ys的不同数据类型
    打印类型:单步-单步打印快速启动
    打印类型:文本-文本快速启动
    打印类型:文本-文本对齐
    绘图类型:矢量场-快速启动
    绘图类型:矢量场-角度和幅值
    绘图类型:矢量场-自定义颜色贴图
    绘图类型:矢量场-自定义比例因子
  定制
    自定义:轴-标题和轴标签
    自定义:轴-标尺模式
    自定义:轴-标尺模式(仅X)
    自定义:轴-原木轴
    自定义:轴-极轴
    自定义:Axis-日期时间轴
    自定义:仅限Axis时间
    自定义:轴-时间代码轴
    自定义:轴-十六进制轴
    自定义:AxisLimits-自动适应数据
    自定义:AxisLimits-具有指定边距的自动拟合
    自定义:轴限制-手动定义轴限制
    自定义:AxisLimits-缩放
    定制:AxisLimits-Pan
    自定义:颜色-默认颜色集
    定制:颜色-Nord Colorset
    定制:颜色-深色配色
    自定义:数字-背景色
    定制:图-角框
    自定义:数字-数字填充
    自定义:数字-无填充
    自定义:图形-抗锯齿
    自定义:网格-隐藏网格
    自定义:网格-网格线宽度
    自定义:网格-网格线样式
    自定义:栅格-定义的栅格间距
    定制:Legend-Legend演示
    自定义:打印样式-打印后修改样式
    自定义:PlotStyle-到处都有自定义字体
    自定义:PlotStyle-图例
    自定义:打印样式-打印样式(默认)
    自定义:打印样式-打印样式(Seaborn)
    自定义:打印样式-打印样式(控件)
    自定义:打印样式-打印样式(蓝色1)
    自定义:打印样式-打印样式(蓝色2)
    自定义:打印样式-打印样式(蓝色3)
    自定义:打印样式-打印样式(Light1)
    自定义:打印样式-打印样式(Light2)
    自定义:打印样式-打印样式(灰色1)
    自定义:打印样式-打印样式(灰色2)
    自定义:打印样式-打印样式(黑色)
    自定义:勾号-隐藏勾号标签
    自定义:记号-数字记号格式
    自定义:刻度-日期时间轴
    自定义:勾号-定义勾号位置
    自定义:刻度-非线性刻度间距
    自定义:滴答声-滴答声递减
    自定义:记号-定义的记号间距
    自定义:记号-本地化格式(匈牙利语)
    自定义:刻度-本地化格式(德语)
    自定义:记号-使用自定义区域性设置记号的格式
    定制:蜱虫-容纳大蜱虫
    自定义:滴答声-倍增符号
    自定义:刻度-偏移符号
    自定义:刻度-旋转的刻度
    自定义:刻度-定义的日期时间刻度间距
  先进的
    高级:条形图-多条形图
    高级:多点-多点快速入门
    高级:多点-匹配子地块轴
    高级:统计-直方图
    高级:统计学-CPH
    高级:统计学-线性回归
    高级:统计-人口统计
    高级:统计学-样条插值
  实验的
    实验:CustomPlottables-手动添加一个Plottable
    实验性:FringeCase-空图
    实验:热图-热图快速入门
    实验:热图-2D波形
    实验:热图-自定义热图
    实验:热图-自定义比例
    实验:热图-XY数据的热图(高斯)
    实验:热图-XY数据的热图(密度)
    实验:热图-热图图像
    实验:热图-热图背景图像

快速入门

快速启动:快速启动-散点图快速启动

散点图最适用于少量成对的X/Y数据点。对于均匀分布的数据点,信号速度要快得多。

// Code from /src/ScottPlot.Demo/Quickstart/Quickstart.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] xs = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(xs, sin, label: "sin");
plt.PlotScatter(xs, cos, label: "cos");
plt.Legend();

plt.Title("Scatter Plot Quickstart");
plt.YLabel("Vertical Units");
plt.XLabel("Horizontal Units");

plt.SaveFig("Quickstart_Quickstart_Scatter.png");

快速入门:快速入门-500万分

信号图类型非常适合显示均匀分布的数据。具有数百万个数据点的绘图可以实时交互。如果基础数据不变,SignalConst()可能是一种更有效的显示方式。

// Code from /src/ScottPlot.Demo/Quickstart/Quickstart.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = (int)1e6;
int lineCount = 5;

for (int i = 0; i < lineCount; i++)
    plt.PlotSignal(DataGen.RandomWalk(rand, pointCount));

plt.Title("Signal Plot Quickstart (5 million points)");
plt.YLabel("Vertical Units");
plt.XLabel("Horizontal Units");

plt.SaveFig("Quickstart_Quickstart_Signal_5MillionPoints.png");

打印类型

打印类型:注释-注释快速启动

注释是固定在图形(而不是数据区域)上的标签,因此它们不会随着轴的调整而移动。

// Code from /src/ScottPlot.Demo/PlotTypes/Annotation.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Range(0, 5, .1);
plt.PlotScatter(xs, DataGen.Sin(xs));
plt.PlotScatter(xs, DataGen.Cos(xs));

// negative coordinates snap text to the lower or right edges
plt.PlotAnnotation("Top Left", 10, 10);
plt.PlotAnnotation("Lower Left", 10, -10);
plt.PlotAnnotation("Top Right", -10, 10);
plt.PlotAnnotation("Lower Right", -10, -10);

// arguments allow customization of style
plt.PlotAnnotation("Fancy Annotation", 10, 40,
    fontSize: 24, fontName: "Impact", fontColor: Color.Red, shadow: true,
    fill: true, fillColor: Color.White, fillAlpha: 1, lineWidth: 2);

plt.SaveFig("PlotTypes_Annotation_AnnotationQuickstart.png");

打印类型:箭头-打印箭头

可以添加箭头,指向绘图上的特定点

// Code from /src/ScottPlot.Demo/PlotTypes/Arrow.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotArrow(25, 0, 27, .2, label: "default");
plt.PlotArrow(27, -.25, 23, -.5, label: "big", lineWidth: 10);
plt.PlotArrow(12, 1, 12, 0, label: "skinny", arrowheadLength: 10);
plt.PlotArrow(20, .6, 20, 1, label: "fat", arrowheadWidth: 10);
plt.Legend(fixedLineWidth: false);

plt.SaveFig("PlotTypes_Arrow_Quickstart.png");

打印类型:AxisLine-AxisLine快速启动

可以使用HLine()和VLine()放置水平线和垂直线。可以使用参数自定义样式。

// Code from /src/ScottPlot.Demo/PlotTypes/AxisLine.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotHLine(y: .85, label: "HLine");
plt.PlotVLine(x: 23, label: "VLine");
plt.PlotVLine(x: 33, label: "VLine too", color: Color.Magenta, lineWidth: 3, lineStyle: LineStyle.Dot);

plt.Grid(lineStyle: LineStyle.Dot);
plt.Legend();

plt.SaveFig("PlotTypes_AxisLine_Quickstart.png");

打印类型:轴线-可拖动轴线

使用参数启用可拖动的行(具有可选限制)。

// Code from /src/ScottPlot.Demo/PlotTypes/AxisLine.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotHLine(y: .85, draggable: true, dragLimitLower: -1, dragLimitUpper: +1);
plt.PlotVLine(x: 23, draggable: true, dragLimitLower: 0, dragLimitUpper: 50);

plt.Grid(lineStyle: LineStyle.Dot);

plt.SaveFig("PlotTypes_AxisLine_Draggable.png");

打印类型:AxisSpan-Axis Span快速启动

可以使用VSpan()和HSpan()放置水平和垂直跨距。可以使用参数自定义样式。

// Code from /src/ScottPlot.Demo/PlotTypes/AxisSpan.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotVSpan(y1: .15, y2: .85, label: "VSpan");
plt.PlotHSpan(x1: 10, x2: 25, label: "HSpan");

plt.Grid(lineStyle: LineStyle.Dot);
plt.Legend();

plt.SaveFig("PlotTypes_AxisSpan_Quickstart.png");

绘图类型:AxisSpan-可拖动的轴跨距

可以使用参数使水平和垂直跨度可拖动(具有可选限制)。按住SHIFT键的同时拖动可调范围的边缘以移动它,而不是调整其大小。

// Code from /src/ScottPlot.Demo/PlotTypes/AxisSpan.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotVSpan(y1: .15, y2: .85, label: "Adjustable VSpan",
    draggable: true, dragLimitLower: -1, dragLimitUpper: 1);

plt.PlotHSpan(x1: 10, x2: 25, label: "Adjustable HSpan",
    draggable: true, dragLimitLower: 0, dragLimitUpper: 50);

plt.PlotVSpan(y1: -.25, y2: -.05, label: "Fixed Size VSpan",
    draggable: true, dragLimitLower: -1, dragLimitUpper: 1,
    dragFixedSize: true);

plt.PlotHSpan(x1: 5, x2: 7, label: "Fixed Size HSpan",
    draggable: true, dragLimitLower: 0, dragLimitUpper: 50,
    dragFixedSize: true);

plt.Grid(lineStyle: LineStyle.Dot);
plt.Legend();

plt.SaveFig("PlotTypes_AxisSpan_Draggable.png");

打印类型:条形-条形打印快速启动

条形图系列可以由supply Xs和Ys创建。(可选)使用参数将errorbars作为第三个数组应用。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random data to plot
string[] labels = { "one", "two", "three", "four", "five" };
int barCount = labels.Length;
Random rand = new Random(0);
double[] xs = DataGen.Consecutive(barCount);
double[] ys = DataGen.RandomNormal(rand, barCount, 20, 5);
double[] yError = DataGen.RandomNormal(rand, barCount, 5, 2);

// make the bar plot
plt.PlotBar(xs, ys, yError);

// customize the plot to make it look nicer
plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);

// apply custom axis tick labels
plt.XTicks(xs, labels);

plt.SaveFig("PlotTypes_Bar_Quickstart.png");

绘图类型:条形图-分组条形图

此示例演示如何显示分组条形图。数据组标签显示为水平轴上的标签,而系列标签显示在图例中。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random data to plot
string[] groupNames = { "one", "two", "three", "four", "five" };
string[] seriesNames = { "alpha", "bravo", "charley" };
int groupCount = groupNames.Length;
Random rand = new Random(0);
double[] ys1 = DataGen.RandomNormal(rand, groupCount, 20, 5);
double[] ys2 = DataGen.RandomNormal(rand, groupCount, 20, 5);
double[] ys3 = DataGen.RandomNormal(rand, groupCount, 20, 5);
double[] err1 = DataGen.RandomNormal(rand, groupCount, 5, 2);
double[] err2 = DataGen.RandomNormal(rand, groupCount, 5, 2);
double[] err3 = DataGen.RandomNormal(rand, groupCount, 5, 2);

plt.PlotBarGroups(
    groupLabels: groupNames,
    seriesLabels: seriesNames,
    ys: new double[][] { ys1, ys2, ys3 },
    yErr: new double[][] { err1, err2, err3 });

// customize the plot to make it look nicer
plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
plt.Legend(location: legendLocation.upperRight);

plt.SaveFig("PlotTypes_Bar_NewMultipleBars.png");

PlotTypes:条形图

此示例演示如何显示带图案的条形图。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random data to plot
string[] groupNames = { "one", "two", "three", "four", "five" };
string[] seriesNames = { "alpha", "bravo", "charley" };
int groupCount = groupNames.Length;
Random rand = new Random(0);
double[] ys1 = DataGen.RandomNormal(rand, groupCount, 20, 5);
double[] ys2 = DataGen.RandomNormal(rand, groupCount, 20, 5);
double[] ys3 = DataGen.RandomNormal(rand, groupCount, 20, 5);
double[] err1 = DataGen.RandomNormal(rand, groupCount, 5, 2);
double[] err2 = DataGen.RandomNormal(rand, groupCount, 5, 2);
double[] err3 = DataGen.RandomNormal(rand, groupCount, 5, 2);

PlottableBar[] barCharts = plt.PlotBarGroups(
    groupLabels: groupNames,
    seriesLabels: seriesNames,
    ys: new double[][] { ys1, ys2, ys3 },
    yErr: new double[][] { err1, err2, err3 });

barCharts[0].hatchStyle = Drawing.HatchStyle.StripedWideUpwardDiagonal;
barCharts[0].fillColor = System.Drawing.Color.Gray;
barCharts[0].hatchColor = System.Drawing.Color.Black;

barCharts[1].hatchStyle = Drawing.HatchStyle.StripedWideDownwardDiagonal;
barCharts[1].fillColor = System.Drawing.Color.DodgerBlue;
barCharts[1].hatchColor = System.Drawing.Color.DeepSkyBlue;

barCharts[2].hatchStyle = Drawing.HatchStyle.LargeCheckerBoard;
barCharts[2].fillColor = System.Drawing.Color.SeaGreen;
barCharts[2].hatchColor = System.Drawing.Color.DarkSeaGreen;

// customize the plot to make it look nicer
plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
plt.Legend(location: legendLocation.upperRight);

plt.SaveFig("PlotTypes_Bar_PatternedMultipleBars.png");

绘图类型:条形图-水平条形图

条形图可以水平显示。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random data to plot
Random rand = new Random(0);
int pointCount = 5;
double[] xs = DataGen.Consecutive(pointCount);
double[] ys = DataGen.RandomNormal(rand, pointCount, 20, 5);
double[] yError = DataGen.RandomNormal(rand, pointCount, 3, 2);

// make the bar plot
plt.PlotBar(xs, ys, yError, horizontal: true);

// customize the plot to make it look nicer
plt.Grid(enableHorizontal: false, lineStyle: LineStyle.Dot);

// apply custom axis tick labels
string[] labels = { "one", "two", "three", "four", "five" };
plt.YTicks(xs, labels);

plt.SaveFig("PlotTypes_Bar_Horizontal.png");

绘图类型:条形图-堆叠条形图

堆叠条形图可以这样创建。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data
double[] xs = { 1, 2, 3, 4, 5, 6, 7 };
double[] valuesA = { 1, 2, 3, 2, 1, 2, 1 };
double[] valuesB = { 3, 3, 2, 1, 3, 2, 1 };

// to simulate stacking B on A, shift B up by A
double[] valuesB2 = new double[valuesB.Length];
for (int i = 0; i < valuesB.Length; i++)
    valuesB2[i] = valuesA[i] + valuesB[i];

// plot the bar charts in reverse order (highest first)
plt.PlotBar(xs, valuesB2, label: "Series B");
plt.PlotBar(xs, valuesA, label: "Series A");

// improve the styling
plt.Legend(location: legendLocation.upperRight);
plt.Title("Stacked Bar Charts");

plt.SaveFig("PlotTypes_Bar_Stacked.png");

绘图类型:条形图-显示条形图上方的值

通过设置“showValues”参数,可以在图形上显示每个条的值。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random data to plot
Random rand = new Random(0);
int pointCount = 10;
double[] xs = DataGen.Consecutive(pointCount);
double[] ys = DataGen.RandomNormal(rand, pointCount, 20, 5);

// let's round the values to simplify display
ys = Tools.Round(ys, 1);

// add both bar plot
plt.PlotBar(xs, ys, showValues: true);

// customize the plot to make it look nicer
plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
plt.Legend();

plt.SaveFig("PlotTypes_Bar_Labels.png");

绘图类型:条形图-瀑布图

瀑布图是一种方框图,其中每个方框从上一个方框结束的地方开始。

// Code from /src/ScottPlot.Demo/PlotTypes/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random monthly data
Random rand = new Random(0);
double[] monthProfits = DataGen.RandomNormal(rand, 12, 5, 10);
double[] monthNumbers = DataGen.Consecutive(12);
string[] monthNames = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

plt.PlotWaterfall(monthNumbers, monthProfits,
    fillColor: Color.Green, negativeColor: Color.Red);

plt.XTicks(monthNames);
plt.YLabel("Valuation (million USD)");
plt.Title("Company Value in 2020");

plt.SaveFig("PlotTypes_Bar_Waterfall.png");

打印类型:Colormap-Colormap快速启动

颜色贴图可以轻松地将分数值(从0到1)转换为颜色。

// Code from /src/ScottPlot.Demo/PlotTypes/Colormap.cs
var plt = new ScottPlot.Plot(600, 400);

int lineCount = 10;
for (int i = 0; i < lineCount; i++)
{
    double[] ys = DataGen.Sin(51, phase: i * .03);
    double fraction = (double)i / lineCount;
    Color c = Drawing.Colormap.Jet.GetColor(fraction);
    plt.PlotSignal(ys, color: c, lineWidth: 2, markerSize: 0);
}

plt.AxisAuto(0);

plt.SaveFig("PlotTypes_Colormap_Quickstart.png");

PlotTypes:ErrorBar-带有不对称ErrorBar的散点图

不对称X和Y误差范围可作为正负误差条的可选双阵列提供

// Code from /src/ScottPlot.Demo/PlotTypes/ErrorBar.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 20;

// random data points
double[] dataX = DataGen.Consecutive(pointCount);
double[] dataY1 = DataGen.RandomNormal(rand, pointCount, mean: 20, stdDev: 2);
double[] dataY2 = DataGen.RandomNormal(rand, pointCount, mean: 10, stdDev: 2);
double[] dataY3 = DataGen.RandomNormal(rand, pointCount, mean: 0, stdDev: 2);

// random errorbar sizes
double[] errorYPositive = DataGen.RandomNormal(rand, pointCount);
double[] errorXPositive = DataGen.RandomNormal(rand, pointCount);
double[] errorYNegative = DataGen.RandomNormal(rand, pointCount);
double[] errorXNegative = DataGen.RandomNormal(rand, pointCount);

// plot different combinations of errorbars
var err1 = plt.PlotErrorBars(dataX, dataY1, errorXPositive, errorXNegative, errorYPositive, errorYNegative);
var err2 = plt.PlotErrorBars(dataX, dataY2, errorXPositive, null, errorYPositive, null);
var err3 = plt.PlotErrorBars(dataX, dataY3, null, errorXNegative, null, errorYNegative);

// draw scatter plots on top of the errorbars
plt.PlotScatter(dataX, dataY1, color: err1.Color, label: "Both");
plt.PlotScatter(dataX, dataY2, color: err2.Color, label: "Positive");
plt.PlotScatter(dataX, dataY3, color: err3.Color, label: $"Negative");

plt.Title("Error Bars with Asymmetric X and Y Values");
plt.Grid(false);
plt.Legend();

plt.SaveFig("PlotTypes_ErrorBar_ErrorBarsAsymmetric.png");

绘图类型:填充-填充曲线

可以创建一个填充散点图,其中曲线和基线之间的区域用颜色着色。基线默认为0,但可以使用可选参数设置。

// Code from /src/ScottPlot.Demo/PlotTypes/Fill.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Range(0, 10, .1, true);
double[] sin = DataGen.Sin(xs);
double[] cos = DataGen.Cos(xs);

plt.PlotFill(xs, sin, "sin", lineWidth: 2, fillAlpha: .5);
plt.PlotFill(xs, cos, "cos", lineWidth: 2, fillAlpha: .5);
plt.PlotHLine(0, color: Color.Black);
plt.AxisAuto(0);
plt.Legend(location: legendLocation.lowerLeft);

plt.SaveFig("PlotTypes_Fill_FillBeneathCurve.png");

绘图类型:填充-曲线之间的填充

通过提供两对X/Y坐标,可以填充曲线之间的区域

// Code from /src/ScottPlot.Demo/PlotTypes/Fill.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Range(0, 10, .1, true);
double[] sin = DataGen.Sin(xs);
double[] cos = DataGen.Cos(xs);

plt.PlotFill(xs, sin, xs, cos, fillAlpha: .5);
plt.PlotScatter(xs, sin, Color.Black);
plt.PlotScatter(xs, cos, Color.Black);

plt.AxisAuto(0);

plt.SaveFig("PlotTypes_Fill_FillBetweenCurves.png");

打印类型:上方填充和下方填充

通过一种特殊方法,可以创建基线上方/下方具有不同颜色的填充线图。

// Code from /src/ScottPlot.Demo/PlotTypes/Fill.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
var ys = ScottPlot.DataGen.RandomWalk(rand, 1000, offset: -10);
var xs = ScottPlot.DataGen.Consecutive(ys.Length, spacing: 0.025);

plt.PlotFillAboveBelow(xs, ys, fillAlpha: .5, labelAbove: "above", labelBelow: "below");
plt.Legend(location: ScottPlot.legendLocation.lowerLeft);
plt.AxisAuto(0);

plt.SaveFig("PlotTypes_Fill_FillAboveBelow.png");

打印类型:填充-使用基线在上方和下方填充

可以提供自定义基线。

// Code from /src/ScottPlot.Demo/PlotTypes/Fill.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
var ys = ScottPlot.DataGen.RandomWalk(rand, 1000, offset: -10);
var xs = ScottPlot.DataGen.Consecutive(ys.Length, spacing: 0.025);

plt.PlotFillAboveBelow(xs, ys, fillAlpha: .5, baseline: 3.21);
plt.AxisAuto(0);

plt.SaveFig("PlotTypes_Fill_FillAboveBelowWithBaseline.png");

绘图类型:财务-财务OHLC图表

通过绘制OHLC对象数组来显示OHLC(打开、高、低、关闭)数据。

// Code from /src/ScottPlot.Demo/PlotTypes/Finance.cs
var plt = new ScottPlot.Plot(600, 400);

ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand: null, pointCount: 60, deltaMinutes: 10);
plt.Title("Open/High/Low/Close (OHLC) Chart");
plt.YLabel("Stock Price (USD)");
plt.PlotOHLC(ohlcs);
plt.Ticks(dateTimeX: true);

plt.SaveFig("PlotTypes_Finance_OHLC.png");

绘图类型:财务-财务烛台图

通过绘制OHLC对象数组来显示烛台数据。

// Code from /src/ScottPlot.Demo/PlotTypes/Finance.cs
var plt = new ScottPlot.Plot(600, 400);

ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand: null, pointCount: 60, deltaMinutes: 10);
plt.Title("Ten Minute Candlestick Chart");
plt.YLabel("Stock Price (USD)");
plt.PlotCandlestick(ohlcs);
plt.Ticks(dateTimeX: true);

plt.SaveFig("PlotTypes_Finance_Candle.png");

情节类型:财务-有缺口的OHLC

此示例演示了默认情况下,水平轴是严格线性的。缺少OHLC数据会在绘图中产生间隙。

// Code from /src/ScottPlot.Demo/PlotTypes/Finance.cs
var plt = new ScottPlot.Plot(600, 400);

ScottPlot.OHLC[] ohlcs = ScottPlot.DataGen.RandomStockPrices(rand: null, pointCount: 30, deltaDays: 1);

plt.Title("Daily Candlestick Chart (weekends skipped)");
plt.YLabel("Stock Price (USD)");
plt.PlotCandlestick(ohlcs);
plt.Ticks(dateTimeX: true);

plt.SaveFig("PlotTypes_Finance_CandleSkipWeekends.png");

情节类型:财务-无空白OHLC

本例演示了如何连续绘制OHLC数据,即使横轴上存在缺口(在市场关闭的几天内)。该策略是将其绘制在线性水平轴(而不是日期时间轴)上,然后稍后返回并定义自定义标记标签。

// Code from /src/ScottPlot.Demo/PlotTypes/Finance.cs
var plt = new ScottPlot.Plot(600, 400);

// start with stock prices which have unevenly spaced time points (weekends are skipped)
ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand: null, pointCount: 30);

// replace timestamps with a series of numbers starting at 0
for (int i = 0; i < ohlcs.Length; i++)
    ohlcs[i].time = i;

// plot the candlesticks (the horizontal axis will start at 0)
plt.Title("Daily Candlestick Chart (evenly spaced)");
plt.YLabel("Stock Price (USD)");
plt.PlotCandlestick(ohlcs);

// create ticks manually
double[] tickPositions = { 0, 6, 13, 20, 27 };
string[] tickLabels = { "Sep 23", "Sep 30", "Oct 7", "Oct 14", "Oct 21" };
plt.XTicks(tickPositions, tickLabels);

plt.SaveFig("PlotTypes_Finance_CandleNoSkippedDays.png");

绘图类型:金融-简单移动平均线(SMA)

本例演示如何绘制OHLC数据,并在顶部显示简单移动平均线(SMA)。

// Code from /src/ScottPlot.Demo/PlotTypes/Finance.cs
var plt = new ScottPlot.Plot(600, 400);

// start with random stock data
Random rand = new Random(0);
ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand, 75, sequential: true);
plt.PlotCandlestick(ohlcs);

// calculate SMAs of different durations using helper methods
double[] xs = DataGen.Consecutive(ohlcs.Length);
double[] sma8xs = xs.Skip(8).ToArray();
double[] sma8ys = Statistics.Finance.SMA(ohlcs, 8).Skip(8).ToArray();
double[] sma20xs = xs.Skip(20).ToArray();
double[] sma20ys = Statistics.Finance.SMA(ohlcs, 20).Skip(20).ToArray();

plt.PlotScatter(sma8xs, sma8ys, label: "8 day SMA", color: Color.Blue, markerSize: 0, lineWidth: 2);
plt.PlotScatter(sma20xs, sma20ys, label: "20 day SMA", color: Color.Navy, markerSize: 0, lineWidth: 2);

// decorate the plot
plt.Title("Simple Moving Averages (SMA)");
plt.YLabel("Stock Price (USD)");
plt.XLabel("Day");
plt.Legend();

plt.SaveFig("PlotTypes_Finance_SimpleMovingAverage.png");

情节类型:金融-布林格乐队

本例演示如何绘制OHLC数据并在顶部显示布林带。

// Code from /src/ScottPlot.Demo/PlotTypes/Finance.cs
var plt = new ScottPlot.Plot(600, 400);

// start with random stock data
Random rand = new Random(0);
ScottPlot.OHLC[] ohlcs = DataGen.RandomStockPrices(rand, 100, sequential: true);
plt.PlotCandlestick(ohlcs);

// calculate Bollinger bands
double[] xs = DataGen.Consecutive(ohlcs.Length);
(var sma, var bolL, var bolU) = ScottPlot.Statistics.Finance.Bollinger(ohlcs, 20);
double[] xs2 = xs.Skip(20).ToArray();
sma = sma.Skip(20).ToArray();
bolL = bolL.Skip(20).ToArray();
bolU = bolU.Skip(20).ToArray();

plt.PlotScatter(xs2, bolL, color: Color.Blue, markerSize: 0);
plt.PlotScatter(xs2, bolU, color: Color.Blue, markerSize: 0);
plt.PlotScatter(xs2, sma, color: Color.Blue, markerSize: 0, lineStyle: LineStyle.Dash);

// decorate the plot
plt.Title("Bollinger Bands");
plt.YLabel("Stock Price (USD)");
plt.XLabel("Day");
plt.Legend();

plt.SaveFig("PlotTypes_Finance_Bollinger.png");

绘图类型:函数-函数绘图

未提供用于创建(绘图)数据点的功能。轴可以无限缩放。

// Code from /src/ScottPlot.Demo/PlotTypes/Function.cs
var plt = new ScottPlot.Plot(600, 400);

var func1 = new Func<double, double?>((x) => Math.Sin(x) * Math.Sin(x / 2));
plt.PlotFunction(func1, lineWidth: 2, label: "sin(x) * sin(x/2)");

var func2 = new Func<double, double?>((x) => Math.Sin(x) * Math.Sin(x / 3));
plt.PlotFunction(func2, lineWidth: 2, label: "sin(x) * sin(x/3)", lineStyle: LineStyle.Dot);

var func3 = new Func<double, double?>((x) => Math.Cos(x) * Math.Sin(x / 5));
plt.PlotFunction(func3, lineWidth: 2, label: "cos(x) * cos(x/5)", lineStyle: LineStyle.Dash);

plt.Title("Plot Mathematical Functions");
plt.Legend();

plt.SaveFig("PlotTypes_Function_Quickstart.png");

打印类型:图像-图像快速启动

图像可以放置在任何X/Y位置,并使用参数设置样式。

// Code from /src/ScottPlot.Demo/PlotTypes/Image.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

Bitmap image = DataGen.SampleImage();
plt.PlotBitmap(image, 0, 0);

plt.SaveFig("PlotTypes_Image_Quickstart.png");

打印类型:图像-图像对齐

可以使用参数自定义图像对齐和旋转。

// Code from /src/ScottPlot.Demo/PlotTypes/Image.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

Bitmap image = DataGen.SampleImage();

plt.PlotBitmap(image, 5, 0.8);
plt.PlotPoint(5, 0.8, color: Color.Green);

plt.PlotBitmap(image, 20, 0.3);
plt.PlotPoint(20, 0.3, color: Color.Black, markerSize: 15);

plt.PlotBitmap(image, 30, 0, alignment: ImageAlignment.middleCenter);
plt.PlotPoint(30, 0, color: Color.Black, markerSize: 15);

plt.PlotBitmap(image, 30, -0.3, alignment: ImageAlignment.upperLeft);
plt.PlotPoint(30, -0.3, color: Color.Black, markerSize: 15);

plt.PlotBitmap(image, 5, -.5, rotation: -30);
plt.PlotPoint(5, -.5, color: Color.Blue, markerSize: 15);

plt.PlotBitmap(image, 15, -.6, frameSize: 3, frameColor: Color.Magenta);

plt.SaveFig("PlotTypes_Image_Alignment.png");

绘图类型:饼图-快速启动

饼图(或圆图)将数字比例表示为圆的切片。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 283, 184, 76, 43 };

plt.PlotPie(values);

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieQuickstart.png");

绘图类型:饼图-分解饼图

有一个选项是“爆炸式”饼图。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 283, 184, 76, 43 };

plt.PlotPie(values, explodedChart: true);

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_ExplodingPie.png");

绘图类型:饼图-甜甜圈绘图

油炸圈饼图是圆心中空的圆形图。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 283, 184, 76, 43 };

var pie = plt.PlotPie(values);
pie.donutSize = .6;
pie.explodedChart = true;

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_DonutPie.png");

绘图类型:饼图-带文本的圆环图

自定义文本可以显示在甜甜圈内。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 779, 586 };
string centerText = $"{values[0] / values.Sum() * 100:00.0}%";

Color color1 = Color.FromArgb(255, 0, 150, 200);
Color color2 = Color.FromArgb(100, 0, 150, 200);

var pie = plt.PlotPie(values);
pie.donutSize = .6;
pie.centerText = centerText;
pie.centerTextColor = color1;
pie.outlineSize = 2;
pie.colors = new Color[] { color1, color2 };

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_DonutPieWithPercentageInDonut.png");

绘图类型:饼图-显示值

有一个选项可以在图表上显示切片值。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 43, 283, 76, 184 };

plt.PlotPie(values, showValues: true);

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieShowValues.png");

绘图类型:饼图-显示百分比

有一个选项可以在图表上显示切片百分比。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 43, 283, 76, 184 };

plt.PlotPie(values, showPercentages: true);

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieShowPercentages.png");

PlotTypes:饼图-在切片中显示标签

标签也可以显示在切片上。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 43, 283, 76, 184 };
string[] labels = { "C#", "JAVA", "Python", "F#", "PHP" };

plt.PlotPie(values, labels, showLabels: true);

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieLabelSlices.png");

绘图类型:图例中的饼图标签

可以为切片添加标签并在图例中显示它们。

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 43, 283, 76, 184 };
string[] labels = { "C#", "JAVA", "Python", "F#", "PHP" };

plt.PlotPie(values, labels, showLabels: false);
plt.Legend();

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieLegend.png");

绘图类型:饼图-显示所有内容

值、百分比、标签和图例

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 43, 283, 76, 184 };
string[] labels = { "C#", "JAVA", "Python", "F#", "PHP" };

plt.PlotPie(values, labels, showPercentages: true, showValues: true, showLabels: true);
plt.Legend();

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieShowEverything.png");

打印类型:饼图-自定义切片标签

显示标签和数据的最好方法是自己制作字符串标签

// Code from /src/ScottPlot.Demo/PlotTypes/Pie.cs
var plt = new ScottPlot.Plot(600, 400);

double[] values = { 778, 43, 283, 76, 184 };
string[] labels = { "C#", "JAVA", "Python", "F#", "PHP" };

labels = Enumerable
    .Range(0, values.Length)
    .Select(i => $"{labels[i]}\n({values[i]})")
    .ToArray();

plt.PlotPie(values, labels);

plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Pie_PieCustomSliceLabels.png");

打印类型:点-打印点

点基本上是带有单个点的散点图。

// Code from /src/ScottPlot.Demo/PlotTypes/Point.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

// draw something to make the plot interesting
plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

// add a few points
plt.PlotPoint(25, 0.8);
plt.PlotPoint(30, 0.3, color: Color.Magenta, markerSize: 15);

plt.SaveFig("PlotTypes_Point_Quickstart.png");

打印类型:多边形-多边形快速启动

成对的X/Y点可用于显示多边形。

// Code from /src/ScottPlot.Demo/PlotTypes/Polygon.cs
var plt = new ScottPlot.Plot(600, 400);

plt.PlotPolygon(
    xs: new double[] { 2, 8, 6, 4 },
    ys: new double[] { 3, 4, 0.5, 1 },
    label: "polygon A", lineWidth: 2, fillAlpha: .8,
    lineColor: System.Drawing.Color.Black);

plt.PlotPolygon(
    xs: new double[] { 3, 2.5, 5 },
    ys: new double[] { 4.5, 1.5, 2.5 },
    label: "polygon B", lineWidth: 2, fillAlpha: .8,
    lineColor: System.Drawing.Color.Black);

plt.Title($"Polygon Demonstration");
plt.Legend();

plt.SaveFig("PlotTypes_Polygon_Quickstart.png");

PlotTypes:多边形填充线打印

多边形的形状看起来像填充的线条图。

// Code from /src/ScottPlot.Demo/PlotTypes/Polygon.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = { 1, 2, 3, 4 };
double[] ys1 = { 1, 3, 1, 2 };
double[] ys2 = { 3, 7, 3, 1 };
double[] ys3 = { 5, 2, 5, 6 };

// plot line data as polygon corners
double[] paddedXs = Tools.Pad(xs, cloneEdges: true);
plt.PlotPolygon(paddedXs, Tools.Pad(ys3), lineWidth: 2, lineColor: Color.Black, fillAlpha: .7);
plt.PlotPolygon(paddedXs, Tools.Pad(ys2), lineWidth: 2, lineColor: Color.Black, fillAlpha: .7);
plt.PlotPolygon(paddedXs, Tools.Pad(ys1), lineWidth: 2, lineColor: Color.Black, fillAlpha: .7);

plt.AxisAuto(0, 0);
plt.Title("Filled Line Plots");

plt.SaveFig("PlotTypes_Polygon_FilledLinePlots.png");

PlotTypes:多边形填充的线图

多边形的形状看起来像堆叠的填充线图。

// Code from /src/ScottPlot.Demo/PlotTypes/Polygon.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = { 1, 2, 3, 4 };
double[] ys1 = { 1, 3, 1, 2 };
double[] ys2 = { 3, 7, 3, 1 };
double[] ys3 = { 5, 2, 5, 6 };

// manually stack plots
ys2 = Enumerable.Range(0, ys2.Length).Select(x => ys2[x] + ys1[x]).ToArray();
ys3 = Enumerable.Range(0, ys2.Length).Select(x => ys3[x] + ys2[x]).ToArray();

double[] paddedXs = Tools.Pad(xs, cloneEdges: true);
plt.PlotPolygon(paddedXs, Tools.Pad(ys3), lineWidth: 2, lineColor: Color.Black);
plt.PlotPolygon(paddedXs, Tools.Pad(ys2), lineWidth: 2, lineColor: Color.Black);
plt.PlotPolygon(paddedXs, Tools.Pad(ys1), lineWidth: 2, lineColor: Color.Black);

plt.AxisAuto(0, 0);
plt.Title("Stacked Filled Line Plots");

plt.SaveFig("PlotTypes_Polygon_FilledLinePlotsStacked.png");

PlotTypes:多边形-使用多个多边形打印多边形

PlotPolygon可以显示数千个多边形,但速度很慢!为此,请使用PlotPolygons。

// Code from /src/ScottPlot.Demo/PlotTypes/Polygons.cs
var plt = new ScottPlot.Plot(600, 400);

int polygonCount = 5_000;
int pointsPerPolygon = 100;
Random rand = new Random(0);

// create polygons and plot them one at a time
for (int i = 0; i < polygonCount; i++)
{
    double polyX = rand.NextDouble() * 100;
    double polyY = rand.NextDouble() * 100;
    double polyR = rand.NextDouble();
    double[] xs = Enumerable.Range(0, pointsPerPolygon).Select(x => polyR * Math.Cos(2.0 * Math.PI * x / pointsPerPolygon) + polyX).ToArray();
    double[] ys = Enumerable.Range(0, pointsPerPolygon).Select(x => polyR * Math.Sin(2.0 * Math.PI * x / pointsPerPolygon) + polyY).ToArray();
    plt.PlotPolygon(xs, ys, fillColor: Color.Green);
}

// customize the plot
plt.EqualAxis = true;
plt.Title($"PlotPolygon with {polygonCount:N0} {pointsPerPolygon}-sided polygons");

plt.SaveFig("PlotTypes_Polygons_BenchmarkPolygon.png");

PlotTypes:多边形-使用多个多边形打印多边形

PlottablePolygons是一种显示大量多边形的速度优化方法。

// Code from /src/ScottPlot.Demo/PlotTypes/Polygons.cs
var plt = new ScottPlot.Plot(600, 400);

int polygonCount = 5_000;
int pointsPerPolygon = 100;
Random rand = new Random(0);

List<List<(double x, double y)>> polys = new List<List<(double x, double y)>>();

// create a List of polygons
for (int i = 0; i < polygonCount; i++)
{
    double polyX = rand.NextDouble() * 100;
    double polyY = rand.NextDouble() * 100;
    double polyR = rand.NextDouble();
    double[] xs = Enumerable.Range(0, pointsPerPolygon).Select(x => polyR * Math.Cos(2.0 * Math.PI * x / pointsPerPolygon) + polyX).ToArray();
    double[] ys = Enumerable.Range(0, pointsPerPolygon).Select(x => polyR * Math.Sin(2.0 * Math.PI * x / pointsPerPolygon) + polyY).ToArray();
    polys.Add(xs.Zip(ys, (xp, yp) => (xp, yp)).ToList());
}

// then plot all the polygons with one command
plt.PlotPolygons(polys, fillColor: Color.Green);

// customize the plot
plt.EqualAxis = true;
plt.Title($"PlotPolygons with {polys.Count:N0} {pointsPerPolygon}-sided polygons");

plt.SaveFig("PlotTypes_Polygons_BenchmarkPolygons.png");

PlotTypes:总体-绘制总体

人口对象可以用Plot打印。人口()。默认的显示格式是在原始数据值和分布曲线的散点图旁边显示一个框须图(显示异常值、四分位数和中值)。

// Code from /src/ScottPlot.Demo/PlotTypes/Populations.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data to represent test scores
Random rand = new Random(0);
double[] scores = DataGen.RandomNormal(rand, 35, 85, 5);

// create a Population object and plot it
var pop = new ScottPlot.Statistics.Population(scores);
plt.PlotPopulations(pop, "scores");

// improve the style of the plot
plt.Title($"Test Scores (mean: {pop.mean:0.00} +/- {pop.stDev:0.00}, n={pop.n})");
plt.YLabel("Score");
plt.Ticks(displayTicksX: false);
plt.Legend();
plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

plt.SaveFig("PlotTypes_Populations_PlotPopulation.png");

绘图类型:总体-统一总体系列

可以将一系列总体绘制为单个对象。一个系列中的每个群体都有相同的风格,一个系列在传说中只出现一次。

// Code from /src/ScottPlot.Demo/PlotTypes/Populations.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data to represent test scores
Random rand = new Random(0);
double[] scoresA = DataGen.RandomNormal(rand, 35, 85, 5);
double[] scoresB = DataGen.RandomNormal(rand, 42, 87, 3);
double[] scoresC = DataGen.RandomNormal(rand, 23, 92, 3);

// collect multiple populations into a PopulationSeries
var poulations = new Statistics.Population[] {
    new Statistics.Population(scoresA),
    new Statistics.Population(scoresB),
    new Statistics.Population(scoresC)
};

// Plot these as a single series (all styled the same, appearing once in legend)
var popSeries = new Statistics.PopulationSeries(poulations);
plt.PlotPopulations(popSeries, "scores");

// improve the style of the plot
plt.Title($"Test Scores by Class");
plt.YLabel("Score");
plt.XTicks(new string[] { "Class A", "Class B", "Class C" });
plt.Legend();
plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

plt.SaveFig("PlotTypes_Populations_PlotPopulationSeriesUniform.png");

绘图类型:总体-唯一总体系列

为了给一个系列中的每个群体赋予不同的风格,将其绘制为一个多系列,其中每个群体只包含一个系列。这样,每个群体都会有一种独特的风格,每个群体都会被列在图例中。

// Code from /src/ScottPlot.Demo/PlotTypes/Populations.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data to represent test scores
Random rand = new Random(0);
double[] scoresA = DataGen.RandomNormal(rand, 35, 85, 5);
double[] scoresB = DataGen.RandomNormal(rand, 42, 87, 3);
double[] scoresC = DataGen.RandomNormal(rand, 23, 92, 3);

// create a unique PopulationSeries for each set of scores
var seriesA = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresA) }, "Class A");
var seriesB = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresB) }, "Class B");
var seriesC = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresC) }, "Class C");

// create a MultiSeries from all the individual series
var multiSeries = new Statistics.PopulationMultiSeries(new Statistics.PopulationSeries[] { seriesA, seriesB, seriesC });
plt.PlotPopulations(multiSeries);

// improve the style of the plot
plt.Title($"Test Scores by Class");
plt.YLabel("Score");
plt.Ticks(displayTicksX: false);
plt.Legend();
plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

plt.SaveFig("PlotTypes_Populations_PlotPopulationSeriesUnique.png");

绘图类型:总体-绘制总体多系列

要比较人口序列的组,请构造一个PopulationMultiSeries对象并将其放入容器中。多系列中的每个系列将在图例中出现一次。

// Code from /src/ScottPlot.Demo/PlotTypes/Populations.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data to represent test scores.
Random rand = new Random(0);

// Each class (A, B, C) is a series.
// Each semester (fall, spring, summer A, summer B) is a group.

double[] scoresAfall = DataGen.RandomNormal(rand, 35, 85, 5);
double[] scoresBfall = DataGen.RandomNormal(rand, 42, 87, 5);
double[] scoresCfall = DataGen.RandomNormal(rand, 23, 82, 5);

double[] scoresAspring = DataGen.RandomNormal(rand, 35, 84, 3);
double[] scoresBspring = DataGen.RandomNormal(rand, 42, 88, 3);
double[] scoresCspring = DataGen.RandomNormal(rand, 23, 84, 3);

double[] scoresAsumA = DataGen.RandomNormal(rand, 35, 80, 5);
double[] scoresBsumA = DataGen.RandomNormal(rand, 42, 90, 5);
double[] scoresCsumA = DataGen.RandomNormal(rand, 23, 85, 5);

double[] scoresAsumB = DataGen.RandomNormal(rand, 35, 91, 2);
double[] scoresBsumB = DataGen.RandomNormal(rand, 42, 93, 2);
double[] scoresCsumB = DataGen.RandomNormal(rand, 23, 90, 2);

// Collect multiple populations into a PopulationSeries.
// All populations in a series will be styled the same and appear once in the legend.

var popsA = new Statistics.Population[] {
    new Statistics.Population(scoresAfall),
    new Statistics.Population(scoresAspring),
    new Statistics.Population(scoresAsumA),
    new Statistics.Population(scoresAsumB)
};

var popsB = new Statistics.Population[] {
    new Statistics.Population(scoresBfall),
    new Statistics.Population(scoresBspring),
    new Statistics.Population(scoresBsumA),
    new Statistics.Population(scoresBsumB)
};

var popsC = new Statistics.Population[] {
    new Statistics.Population(scoresCfall),
    new Statistics.Population(scoresCspring),
    new Statistics.Population(scoresCsumA),
    new Statistics.Population(scoresCsumB)
};

var seriesA = new Statistics.PopulationSeries(popsA, "Class A");
var seriesB = new Statistics.PopulationSeries(popsB, "Class B");
var seriesC = new Statistics.PopulationSeries(popsC, "Class C");
var allSeries = new Statistics.PopulationSeries[] { seriesA, seriesB, seriesC };

// create a MultiSeries from multiple population series and plot it
var multiSeries = new Statistics.PopulationMultiSeries(allSeries);
plt.PlotPopulations(multiSeries);

// improve the style of the plot
plt.Title($"Test Scores by Class");
plt.YLabel("Score");
plt.XTicks(new string[] { "Fall", "Spring", "Summer A", "Summer B" });
plt.Legend();
plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

plt.SaveFig("PlotTypes_Populations_PlotPopulationMultiSeries.png");

打印类型:总体-高级样式

存储Plot返回的对象。Populations()并修改其属性,以进一步自定义组图的显示方式。

// Code from /src/ScottPlot.Demo/PlotTypes/Populations.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data to represent test scores
Random rand = new Random(0);
double[] scoresA = DataGen.RandomNormal(rand, 35, 72, 7);
double[] scoresB = DataGen.RandomNormal(rand, 42, 57, 10);
double[] scoresC = DataGen.RandomNormal(rand, 23, 79, 5);

// create a unique PopulationSeries for each set of scores
var seriesA = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresA) }, "Class A");
var seriesB = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresB) }, "Class B");
var seriesC = new Statistics.PopulationSeries(new Statistics.Population[] { new Statistics.Population(scoresC) }, "Class C");

// create a MultiSeries from all the individual series
var multiSeries = new Statistics.PopulationMultiSeries(new Statistics.PopulationSeries[] { seriesA, seriesB, seriesC });

// save the plottable and modify its properties to customize display style
var popPlot = plt.PlotPopulations(multiSeries);
popPlot.displayDistributionCurve = true;
popPlot.distributionCurveLineStyle = LineStyle.Dash;
popPlot.scatterOutlineColor = System.Drawing.Color.Transparent;
popPlot.displayItems = PlottablePopulations.DisplayItems.ScatterAndBox;
popPlot.boxStyle = PlottablePopulations.BoxStyle.BarMeanStDev;
plt.Axis(y1: 0);

// colors are managed at the population series level:
foreach (var popSeries in popPlot.popMultiSeries.multiSeries)
    popSeries.color = Tools.GetRandomColor(rand);

// improve the style of the plot
plt.Title($"Test Scores by Class");
plt.YLabel("Score");
plt.Legend(location: legendLocation.lowerLeft);
plt.Ticks(displayTicksX: false);
plt.Grid(lineStyle: LineStyle.Dot, enableVertical: false);

plt.SaveFig("PlotTypes_Populations_AdvancedStyling.png");

绘图类型:雷达-快速启动

雷达图简洁地显示多个值。雷达图也称为蜘蛛图或星图。

// Code from /src/ScottPlot.Demo/PlotTypes/Radar.cs
var plt = new ScottPlot.Plot(600, 400);

double[,] values = {
    { 78, 83, 84, 76, 43 },
    { 100, 50, 70, 60, 90 }
};

plt.PlotRadar(values);

// customize the plot
plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);

plt.SaveFig("PlotTypes_Radar_RadarQuickstart.png");

绘图类型:雷达-带标签的雷达

标签可以显示在雷达图的臂上。

// Code from /src/ScottPlot.Demo/PlotTypes/Radar.cs
var plt = new ScottPlot.Plot(600, 400);

double[,] values = { { 5, 3, 10, 15, 3, 2 }, { 5, 2, 10, 10, 1, 4 }, };
string[] categories = { "Wins", "Poles", "Podiums", "Points Finishes", "DNFs", "Fastest Laps" };
string[] groups = { "Sebastian Vettel", "Fernando Alonso" };

plt.PlotRadar(values, categories, groups);
plt.Legend();

// customize the plot
plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);
plt.Title("2010 Formula One World Championship");

/* Data represents the 2010 Formula One World Championship
 * https://en.wikipedia.org/wiki/2010_Formula_One_World_Championship
 * Note: Alonso did not finish (DNF) in the Malaysian GP, but was included 
 * here because he completed >90% of the race distance.
 */

plt.SaveFig("PlotTypes_Radar_RadarWithLabels.png");

绘图类型:比例尺-比例尺

可以在任何绘图的角落添加L形比例尺

// Code from /src/ScottPlot.Demo/PlotTypes/ScaleBar.cs
var plt = new ScottPlot.Plot(600, 400);

// plot some data
plt.PlotSignal(DataGen.Sin(51));
plt.PlotSignal(DataGen.Cos(51, mult: 1.5));

// add the scalebar
plt.PlotScaleBar(5, .25, "5 ms", "250 pA");

// remove axis and grid lines
plt.Grid(false);
plt.Frame(false);
plt.Ticks(false, false);
plt.AxisAuto(0);
plt.TightenLayout(0);

plt.SaveFig("PlotTypes_ScaleBar_ScaleBarQuickstart.png");

绘图类型:散点-散点图快速启动

散点图最适用于少量成对的X/Y数据点。对于均匀分布的数据点,信号速度要快得多。

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.SaveFig("PlotTypes_Scatter_Quickstart.png");

打印类型:散布-自定义标记

参数允许自定义标记

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin, markerSize: 15, markerShape: MarkerShape.openCircle);
plt.PlotScatter(x, cos, markerSize: 7, markerShape: MarkerShape.filledSquare);

plt.SaveFig("PlotTypes_Scatter_CustomizeMarkers.png");

打印类型:散布-所有标记形状

此图显示了所有可用的标记

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);

string[] markerShapeNames = Enum.GetNames(typeof(MarkerShape));
for (int i = 0; i < markerShapeNames.Length; i++)
{
    string markerShapeName = markerShapeNames[i];
    MarkerShape markerShape = (MarkerShape)Enum.Parse(typeof(MarkerShape), markerShapeName);
    double[] sin = DataGen.Sin(pointCount, 2, -i);
    plt.PlotScatter(x, sin, label: markerShapeName, markerShape: markerShape, markerSize: 7);
}

plt.Grid(false);
plt.Legend(fontSize: 10);

plt.SaveFig("PlotTypes_Scatter_AllMarkers.png");

打印类型:散布-自定义线

参数允许自定义线条颜色、大小和图案。将markerSize设置为0可防止渲染标记。

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);
double[] cos2 = DataGen.Cos(pointCount, mult: -1);

plt.PlotScatter(x, sin, color: Color.Magenta, label: "sin", lineWidth: 0, markerSize: 10);
plt.PlotScatter(x, cos, color: Color.Green, label: "cos", lineWidth: 5, markerSize: 0);
plt.PlotScatter(x, cos2, color: Color.Blue, label: "-cos", lineWidth: 3, markerSize: 0, lineStyle: LineStyle.DashDot);

plt.Legend(fixedLineWidth: false);

plt.SaveFig("PlotTypes_Scatter_CustomizeLines.png");

绘图类型:散布-随机X/Y点

散点图的X数据不必均匀分布,因此散点图非常适合显示这样的随机数据。

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 51;
double[] xs1 = DataGen.RandomNormal(rand, pointCount, 1);
double[] xs2 = DataGen.RandomNormal(rand, pointCount, 3);
double[] ys1 = DataGen.RandomNormal(rand, pointCount, 5);
double[] ys2 = DataGen.RandomNormal(rand, pointCount, 7);

plt.PlotScatter(xs1, ys1, markerSize: 0, label: "lines only");
plt.PlotScatter(xs2, ys2, lineWidth: 0, label: "markers only");
plt.Legend();

plt.SaveFig("PlotTypes_Scatter_RandomXY.png");

绘图类型:散点-带有错误条的散点图

X和Y误差范围可以作为可选的双阵列提供

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 20;

for (int plotNumber = 0; plotNumber < 3; plotNumber++)
{
    // create random data to plot
    double[] dataX = new double[pointCount];
    double[] dataY = new double[pointCount];
    double[] errorY = new double[pointCount];
    double[] errorX = new double[pointCount];
    for (int i = 0; i < pointCount; i++)
    {
        dataX[i] = i + rand.NextDouble();
        dataY[i] = rand.NextDouble() * 100 + 100 * plotNumber;
        errorX[i] = rand.NextDouble();
        errorY[i] = rand.NextDouble() * 10;
    }

    // demonstrate different ways to plot errorbars
    if (plotNumber == 0)
        plt.PlotScatter(dataX, dataY, lineWidth: 0, errorY: errorY, errorX: errorX, label: $"X and Y errors");
    else if (plotNumber == 1)
        plt.PlotScatter(dataX, dataY, lineWidth: 0, errorY: errorY, label: $"Y errors only");
    else
        plt.PlotScatter(dataX, dataY, errorY: errorY, errorX: errorX, label: $"Connected Errors");
}

plt.SaveFig("PlotTypes_Scatter_ErrorBars.png");

PlotTypes:散点-保存散点图数据

许多情节类型都有自己的特点。SaveCSV()方法

// Code from /src/ScottPlot.Demo/PlotTypes/Scatter.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] dataXs = DataGen.Consecutive(pointCount);
double[] dataSin = DataGen.Sin(pointCount);

var scatter = plt.PlotScatter(dataXs, dataSin);
scatter.SaveCSV("scatter.csv");

plt.SaveFig("PlotTypes_Scatter_SaveData.png");

PlotTypes:ScatterHighlight-高亮显示散点图快速启动

允许在散点图上显示照明点

// Code from /src/ScottPlot.Demo/PlotTypes/ScatterHighlight.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 100;
Random rand = new Random(0);
double[] xs = DataGen.Consecutive(pointCount, 0.1);
double[] ys = DataGen.NoisySin(rand, pointCount);

// optional arguments customize highlighted point color, shape, and size
var sph = plt.PlotScatterHighlight(xs, ys);

// you can clear previously-highlighted points
sph.HighlightPoint(4);
sph.HighlightClear();

// highlight the point nearest an X (or Y) position
plt.PlotVLine(8.123, lineStyle: LineStyle.Dash);
sph.HighlightPointNearestX(8.123);

// or highlight the point nearest another point in 2D space
plt.PlotPoint(4.43, 1.48);
sph.HighlightPointNearest(4.43, 1.48);

plt.SaveFig("PlotTypes_ScatterHighlight_Quickstart.png");

绘图类型:信号-信号绘图快速启动

信号图适用于具有数千或数百万个点的等间距数据。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

double[] signalData = DataGen.RandomWalk(null, 100_000);
double sampleRateHz = 20000;

plt.Title($"Signal Plot ({signalData.Length.ToString("N0")} points)");
plt.PlotSignal(signalData, sampleRateHz);

plt.SaveFig("PlotTypes_Signal_Quickstart.png");

PlotTypes:信号样式的信号图

带有样式线和标记的信号图

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] ys = DataGen.RandomWalk(rand, 500);

plt.Title($"Styled Signal Plot");
plt.PlotSignal(ys, yOffset: 40, label: "default");
plt.PlotSignal(ys, yOffset: 20, label: "pink dashed",
    color: Color.Magenta, lineStyle: LineStyle.Dash);
plt.PlotSignal(ys, yOffset: 00, lineWidth: 3, label: "thick solid");
plt.Legend();

plt.SaveFig("PlotTypes_Signal_CustomLineAndMarkers.png");

绘图类型:信号-500万点

具有数百万个点的信号图可以实时交互。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 1_000_000;
int lineCount = 5;

for (int i = 0; i < lineCount; i++)
    plt.PlotSignal(DataGen.RandomWalk(rand, pointCount));

plt.SaveFig("PlotTypes_Signal_RandomWalk_5millionPoints_Signal.png");

PlotTypes:信号-保存信号打印数据

许多情节类型都有自己的特点。SaveCSV()方法

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] dataSin = DataGen.Sin(pointCount);

var scatter = plt.PlotSignal(dataSin);
scatter.SaveCSV("signal.csv");

plt.SaveFig("PlotTypes_Signal_SaveData.png");

绘图类型:信号-显示数据密度

在绘制高密度数据时,您无法始终看到所有重叠数据点下的趋势。如果向PlotSignal()发送颜色数组,它将使用这些颜色来显示密度。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

// create an extremely noisy signal with a subtle sine wave beneath it
Random rand = new Random(0);
int pointCount = 100_000;
double[] signal1 = ScottPlot.DataGen.Sin(pointCount, 3);
double[] noise = ScottPlot.DataGen.RandomNormal(rand, pointCount, 0, 5);
double[] data = new double[pointCount];
for (int i = 0; i < data.Length; i++)
    data[i] = signal1[i] + noise[i];

// plot the noisy signal using the traditional method
plt.PlotSignal(data, yOffset: -40, color: Color.Red);

// use a color array for displaying data from low to high density
Color[] colors = new Color[]
{
    ColorTranslator.FromHtml("#440154"),
    ColorTranslator.FromHtml("#39568C"),
    ColorTranslator.FromHtml("#1F968B"),
    ColorTranslator.FromHtml("#73D055"),
};

plt.PlotSignal(data, colorByDensity: colors);

plt.Title("Color by Density vs. Solid Color");
plt.AxisAuto(0, .1);

plt.SaveFig("PlotTypes_Signal_Density.png");

绘图类型:信号-显示前N个点

在绘制实时数据时,在内存中分配一个大数组,然后在数组中填充值是很有用的。通过将散点图的maxRenderIndex属性设置为,可以防止渲染数组的结尾(该数组可能充满了零)。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

// Allocate memory for a large number of data points
double[] data = new double[1_000_000]; // start with all zeros

// Only populate the first few points with real data
Random rand = new Random(0);
int lastValueIndex = 1234;
for (int i = 1; i <= lastValueIndex; i++)
    data[i] = data[i - 1] + rand.NextDouble() - .5;

// A regular Signal plot would display a little data at the start but mostly zeros.
// Using the maxRenderIndex argument allows one to just plot the first N data points.
var sig = plt.PlotSignal(data, maxRenderIndex: 500);
plt.Title("Partial Display of a 1,000,000 Element Array");
plt.YLabel("Value");
plt.XLabel("Array Index");

// you can change the points to plot later (useful for live plots of incoming data)
sig.maxRenderIndex = 1234;
plt.AxisAuto();

plt.SaveFig("PlotTypes_Signal_FirstNPoints.png");

绘图类型:信号-绘制一系列点

有时只显示源数据数组范围内的值很有用。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 100_000);

plt.PlotSignal(data, minRenderIndex: 4000, maxRenderIndex: 5000);

plt.Title($"Partial Display of a {data.Length} values");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_Signal_PlotRange.png");

绘图类型:信号-填充如下

还可以使用“填充”属性显示范围内的值。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 10_000);

var sig = plt.PlotSignal(data);
sig.minRenderIndex = 4000;
sig.maxRenderIndex = 5000;
sig.fillType = FillType.FillBelow;
sig.fillColor1 = Color.Blue;

plt.Title($"Partial Display of a {data.Length} values using fill");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_Signal_PlotFillRange.png");

绘图类型:信号-下方的渐变填充

在图形下方使用渐变填充绘制一系列值。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 100_000);

var sig = plt.PlotSignal(data);
sig.minRenderIndex = 4000;
sig.maxRenderIndex = 5000;
sig.fillType = FillType.FillBelow;
sig.fillColor1 = Color.Blue;
sig.gradientFillColor1 = Color.Transparent;

plt.Title($"Partial Display of a {data.Length} values using gradient fill below");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_Signal_PlotGradientFillRange.png");

绘图类型:信号-上面的渐变填充

在图形上方使用渐变填充绘制一系列值。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 100_000);
var sig = plt.PlotSignal(data);
sig.minRenderIndex = 4000;
sig.maxRenderIndex = 5000;
sig.fillType = FillType.FillAbove;
sig.fillColor1 = Color.Blue;
sig.gradientFillColor1 = Color.Transparent;
plt.Title($"Partial Display of a {data.Length} values using gradient fill above");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_Signal_PlotGradientFillAboveRange.png");

绘图类型:信号-上下填充

使用“上下填充”打印一系列值。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 100_000);

var sig = plt.PlotSignal(data);
sig.minRenderIndex = 4000;
sig.maxRenderIndex = 5000;
sig.fillType = FillType.FillAboveAndBelow;
sig.fillColor1 = Color.Green;
sig.gradientFillColor1 = Color.Green;
sig.fillColor2 = Color.Red;
sig.gradientFillColor2 = Color.Red;
sig.baseline = -35;

plt.Title($"Partial Display of a {data.Length} values using fill above and below");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_Signal_PlotFillAboveAndBelowRange.png");

绘图类型:信号-上下渐变填充

在上方和下方使用渐变填充绘制一系列值。

// Code from /src/ScottPlot.Demo/PlotTypes/Signal.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 100_000);

plt.Style(Style.Gray1);
plt.Colorset(Colorset.OneHalfDark);

var sig = plt.PlotSignal(data);
sig.minRenderIndex = 4000;
sig.maxRenderIndex = 5000;
sig.markerSize = 0;
sig.color = Color.Black;
sig.fillType = FillType.FillAboveAndBelow;
sig.fillColor1 = Color.FromArgb(255, 44, 160, 44); // Green
sig.gradientFillColor1 = Color.Transparent;
sig.fillColor2 = Color.FromArgb(255, 214, 39, 40); // Red
sig.gradientFillColor2 = Color.Transparent;
sig.baseline = -35;

plt.Title($"Partial Display of a {data.Length} values using gradient fill above and below");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_Signal_PlotGradientFillAboveAndBelowRange.png");

绘图类型:SignalConst-500万点

SignalConst plots预处理数据,以比Signal plots渲染快得多。预处理需要提前一点时间,需要4倍的信号存储。

// Code from /src/ScottPlot.Demo/PlotTypes/SignalConst.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 1_000_000;
int lineCount = 5;

for (int i = 0; i < lineCount; i++)
    plt.PlotSignalConst(DataGen.RandomWalk(rand, pointCount));

plt.SaveFig("PlotTypes_SignalConst_RandomWalk_5millionPoints_SignalConst.png");

绘图类型:SignalConst-上下渐变填充

使用上下渐变填充绘制一系列值。

// Code from /src/ScottPlot.Demo/PlotTypes/SignalConst.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] data = DataGen.RandomWalk(rand, 100_000);

plt.Style(Style.Gray1);
plt.Colorset(Colorset.OneHalfDark);

var sig = plt.PlotSignalConst(data);
sig.minRenderIndex = 4000;
sig.maxRenderIndex = 5000;
sig.markerSize = 0;
sig.color = Color.Black;
sig.fillType = FillType.FillAboveAndBelow;
sig.fillColor1 = Color.FromArgb(255, 44, 160, 44); // Green
sig.gradientFillColor1 = Color.Transparent;
sig.fillColor2 = Color.FromArgb(255, 214, 39, 40); // Red
sig.gradientFillColor2 = Color.Transparent;
sig.baseline = -35;

plt.Title($"SignalConst displaying {data.Length} values");
plt.YLabel("Value");
plt.XLabel("Array Index");
plt.AxisAutoX(margin: 0);

plt.SaveFig("PlotTypes_SignalConst_PlotGradientFillAboveAndBelowRange.png");

绘图类型:SignalXY-带有X和Y数据的信号

SignalXY是一种速度优化图,用于显示具有不均匀间隔位置(Xs)的变量(Y),这些变量按升序排列。如果数据间隔均匀,则Signal和SignalConst会更快。

// Code from /src/ScottPlot.Demo/PlotTypes/SignalXY.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random, unevenly-spaced data
Random rand = new Random(0);
int pointCount = 100_000;
double[] ys = new double[pointCount];
double[] xs = new double[pointCount];
for (int i = 1; i < ys.Length; i++)
{
    ys[i] = ys[i - 1] + rand.NextDouble() - .5;
    xs[i] = xs[i - 1] + rand.NextDouble();
}

plt.Title($"SignalXY Plot ({pointCount:N0} points)");
plt.PlotSignalXY(xs, ys);

plt.SaveFig("PlotTypes_SignalXY_Quickstart.png");

打印类型:SignalXY-大间隙

带有包含间隙的已定义X的信号

// Code from /src/ScottPlot.Demo/PlotTypes/SignalXY.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 1_000_000;

double[] sine = ScottPlot.DataGen.Sin(pointCount, 3);
double[] noise = ScottPlot.DataGen.RandomNormal(rand, pointCount, 0, 0.5);

double[] ys = sine.Zip(noise, (s, n) => s + n).ToArray();

double[] xs = Enumerable.Range(0, pointCount)
    .Select(x => (double)x)
    .Select(x => x > 500_000 ? x + 1_000_000 : x)
    .Select(x => x > 200_000 ? x + 100_000 : x)
    .ToArray();

plt.PlotSignalXY(xs, ys);

plt.SaveFig("PlotTypes_SignalXY_HasXGaps.png");

打印类型:SignalXY-不同密度

具有mised低密度和高密度数据的信号

// Code from /src/ScottPlot.Demo/PlotTypes/SignalXY.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 1_000_000;

double[] sine = ScottPlot.DataGen.Sin(pointCount, 3);
double[] noise = ScottPlot.DataGen.RandomNormal(rand, pointCount, 0, 0.5);

double[] ys = sine.Zip(noise, (s, n) => s + n).ToArray();

double[] xs = new double[pointCount];
double currentX = 0;
for (int i = 0; i < pointCount; i++)
{
    if ((i % 100000) < 10)
        currentX += 10;
    else
        currentX += 0.0001;
    xs[i] = currentX;
}
plt.PlotSignalXY(xs, ys);

plt.SaveFig("PlotTypes_SignalXY_SignalWithDifferentDensity.png");

绘图类型:SignalXYConst-带有X和Y数据的SignalConst

SignalXYConst是一种速度优化图,用于显示具有升序不均匀间隔位置(X)的值(Y)。如果数据间隔均匀,则Signal和SignalConst会更快。

// Code from /src/ScottPlot.Demo/PlotTypes/SignalXYConst.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random, unevenly-spaced data
Random rand = new Random(0);
int pointCount = 100_000;
double[] ys = new double[pointCount];
double[] xs = new double[pointCount];
for (int i = 1; i < ys.Length; i++)
{
    ys[i] = ys[i - 1] + rand.NextDouble() - .5;
    xs[i] = xs[i - 1] + rand.NextDouble();
}

plt.Title($"SignalXY Plot ({pointCount:N0} points)");
plt.PlotSignalXYConst(xs, ys);

plt.SaveFig("PlotTypes_SignalXYConst_Quickstart.png");

PlotTypes:SignalXYConst-xs和ys的不同数据类型

带有(int)Xs和(float)Ys阵列的SignalXYConst

// Code from /src/ScottPlot.Demo/PlotTypes/SignalXYConst.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 1_000_000;

double[] sine = ScottPlot.DataGen.Sin(pointCount, 3);
double[] noise = ScottPlot.DataGen.RandomNormal(rand, pointCount, 0, 0.5);

float[] ys = sine.Zip(noise, (s, n) => s + n).Select(x => (float)x).ToArray();

int[] xs = Enumerable.Range(0, pointCount)
    .Select(x => (int)x)
    .Select(x => x > 500_000 ? x + 1_000_000 : x)
    .Select(x => x > 200_000 ? x + 100_000 : x)
    .ToArray();

plt.PlotSignalXYConst(xs, ys);

plt.SaveFig("PlotTypes_SignalXYConst_MixedDataTypes.png");

打印类型:单步-单步打印快速启动

阶梯图实际上只是散点图,其点通过肘部而不是直线连接。

// Code from /src/ScottPlot.Demo/PlotTypes/Step.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotStep(x, sin);
plt.PlotStep(x, cos);

plt.SaveFig("PlotTypes_Step_Quickstart.png");

打印类型:文本-文本快速启动

文本可以放置在任何X/Y位置,并使用参数设置样式。

// Code from /src/ScottPlot.Demo/PlotTypes/Text.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotText("demo text", 10, .5, fontName: "comic sans ms", fontSize: 42, color: Color.Magenta, bold: true);

plt.SaveFig("PlotTypes_Text_Quickstart.png");

打印类型:文本-文本对齐

可以使用参数自定义文本对齐和旋转。

// Code from /src/ScottPlot.Demo/PlotTypes/Text.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.PlotPoint(25, 0.8, color: Color.Green);
plt.PlotText(" important point", 25, 0.8, color: Color.Green);

plt.PlotPoint(30, 0.3, color: Color.Black, markerSize: 15);
plt.PlotText(" default alignment", 30, 0.3, fontSize: 16, bold: true, color: Color.Magenta);

plt.PlotPoint(30, 0, color: Color.Black, markerSize: 15);
plt.PlotText("middle center", 30, 0, fontSize: 16, bold: true, color: Color.Magenta, alignment: TextAlignment.middleCenter);

plt.PlotPoint(30, -0.3, color: Color.Black, markerSize: 15);
plt.PlotText("upper left", 30, -0.3, fontSize: 16, bold: true, color: Color.Magenta, alignment: TextAlignment.upperLeft);

plt.PlotPoint(5, -.5, color: Color.Blue, markerSize: 15);
plt.PlotText(" Rotated Text", 5, -.5, fontSize: 16, color: Color.Blue, bold: true, rotation: -30);

plt.PlotText("Framed Text", 15, -.6, fontSize: 16, color: Color.White, bold: true, frame: true, frameColor: Color.DarkRed);

plt.SaveFig("PlotTypes_Text_Alignment.png");

绘图类型:矢量场-快速启动

向量场可以用来显示由微分方程解释的数据

// Code from /src/ScottPlot.Demo/PlotTypes/VectorField.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xPositions = DataGen.Range(0, 10);
double[] yPositions = DataGen.Range(0, 10);
Vector2[,] vectors = new Vector2[xPositions.Length, yPositions.Length];

for (int x = 0; x < xPositions.Length; x++)
    for (int y = 0; y < yPositions.Length; y++)
        vectors[x, y] = new Vector2(
            x: Math.Sin(xPositions[x]),
            y: Math.Sin(yPositions[y]));

plt.PlotVectorField(vectors, xPositions, yPositions);

plt.SaveFig("PlotTypes_VectorField_Quickstart.png");

绘图类型:矢量场-角度和幅值

这个例子演示了如何根据给定的角度和大小定义向量。

// Code from /src/ScottPlot.Demo/PlotTypes/VectorField.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Range(-5, 6);
double[] ys = DataGen.Range(-5, 6);
Vector2[,] vectors = new Vector2[xs.Length, ys.Length];

for (int i = 0; i < xs.Length; i++)
{
    for (int j = 0; j < ys.Length; j++)
    {
        double slope = -xs[i];
        double magnitude = Math.Abs(xs[i]);
        double angle = Math.Atan(slope);

        vectors[i, j] = new Vector2(Math.Cos(angle) * magnitude, Math.Sin(angle) * magnitude);
    }
}

plt.PlotVectorField(vectors, xs, ys);

plt.SaveFig("PlotTypes_VectorField_WithChangeingMagnitude.png");

绘图类型:矢量场-自定义颜色贴图

可以根据颜色箭头的大小为其提供颜色贴图

// Code from /src/ScottPlot.Demo/PlotTypes/VectorField.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Range(-5, 5, .5);
double[] ys = DataGen.Range(-5, 5, .5);
Vector2[,] vectors = new Vector2[xs.Length, ys.Length];
double r = 0.5;

for (int i = 0; i < xs.Length; i++)
{
    for (int j = 0; j < ys.Length; j++)
    {
        double x = ys[j];
        double y = -9.81 / r * Math.Sin(xs[i]);

        vectors[i, j] = new Vector2(x, y);
    }
}

plt.PlotVectorField(vectors, xs, ys, colormap: Drawing.Colormap.Turbo);
plt.XLabel("θ");
plt.YLabel("dθ/dt");

plt.SaveFig("PlotTypes_VectorField_Pendulum.png");

绘图类型:矢量场-自定义比例因子

自定义比例因子可以调整箭头的长度。

// Code from /src/ScottPlot.Demo/PlotTypes/VectorField.cs
var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Range(-1.5, 1.5, .25);
double[] ys = DataGen.Range(-1.5, 1.5, .25);
Vector2[,] vectors = new Vector2[xs.Length, ys.Length];

for (int i = 0; i < xs.Length; i++)
{
    for (int j = 0; j < ys.Length; j++)
    {
        double x = xs[i];
        double y = ys[j];
        var e = Math.Exp(-x * x - y * y);
        var dx = (1 - 2 * x * x) * e;
        var dy = -2 * x * y * e;

        vectors[i, j] = new Vector2(dx, dy);
    }
}

plt.PlotVectorField(vectors, xs, ys, scaleFactor: 0.3);

plt.SaveFig("PlotTypes_VectorField_CustomScaleFactor.png");

定制

自定义:轴-标题和轴标签

可以使用参数定义和保管标题和轴标签。

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

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

plt.SaveFig("Customize_Axis_AxisLabels.png");

自定义:轴-标尺模式

标尺模式是显示轴刻度标签的另一种方式

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Ticks(rulerModeX: true, rulerModeY: true);

plt.SaveFig("Customize_Axis_RulerMode.png");

自定义:轴-标尺模式(仅X)

仅在一个轴上显示标尺

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Ticks(rulerModeX: true, displayTicksY: false);
plt.Frame(left: false, right: false, top: false);
plt.TightenLayout(padding: 0, render: true);

plt.SaveFig("Customize_Axis_RulerModeXOnly.png");

自定义:轴-原木轴

ScottPlot只能在线性二维平面上显示数据,但是可以在打印数据之前对其进行日志变换,以显示日志比例。为对数间隔的小刻度自定义刻度选项进一步改善了这些图形的外观。

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

// generate some interesting log-distributed data
int pointCount = 200;
double[] dataXs = new double[pointCount];
double[] dataYs = new double[pointCount];
Random rand = new Random(0);
for (int i = 0; i < pointCount; i++)
{
    double x = 10.0 * i / pointCount;
    dataXs[i] = x;
    dataYs[i] = Math.Pow(2, x) + rand.NextDouble() * i;
}

// this tool can convert linear data to log data
double[] dataYsLog = ScottPlot.Tools.Log10(dataYs);
plt.PlotScatter(dataXs, dataYsLog, lineWidth: 0);

// call this to move minor ticks to simulate a log scale
plt.Ticks(logScaleY: true);

plt.Title("Data (Log Scale)");
plt.YLabel("Vertical Units (10^x)");
plt.XLabel("Horizontal Units");

plt.SaveFig("Customize_Axis_LogAxis.png");

自定义:轴-极轴

辅助函数将半径和θ数组转换为笛卡尔坐标,适用于使用传统打印类型打印。

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

// create some data with polar coordinates
int count = 400;
double step = 0.01;

double[] rs = new double[count];
double[] thetas = new double[count];

for (int i = 0; i < rs.Length; i++)
{
    rs[i] = 1 + i * step;
    thetas[i] = i * 2 * Math.PI * step;
}

// convert polar data to Cartesian data
(double[] xs, double[] ys) = ScottPlot.Tools.ConvertPolarCoordinates(rs, thetas);

// plot the Cartesian data
plt.PlotScatter(xs, ys);
plt.Title("Scatter Plot of Polar Data");
plt.EqualAxis = true;

plt.SaveFig("Customize_Axis_PolarAxis.png");

自定义:Axis-日期时间轴

轴刻度标签可以显示DateTime格式,如果是DateTime。ToOADate()用于绘制数据

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] ys = DataGen.RandomWalk(rand, 100);
double[] xs = new double[ys.Length];

DateTime dtStart = new DateTime(1985, 9, 24);
for (int i = 0; i < ys.Length; i++)
{
    DateTime dtNow = dtStart.AddSeconds(i);
    xs[i] = dtNow.ToOADate();
}

plt.PlotScatter(xs, ys);
plt.Ticks(dateTimeX: true);
plt.Title("DateTime Axis Labels");

plt.SaveFig("Customize_Axis_DateTimeAxis.png");

自定义:仅限Axis时间

通常,日期时间刻度标签显示日期和时间,但通过自己定义格式,可以自定义此行为。

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] ys = DataGen.RandomWalk(rand, 50);
double[] xs = new double[ys.Length];

DateTime start = new DateTime(1985, 9, 24);
for (int i = 0; i < ys.Length; i++)
{
    DateTime dtNow = start.AddMinutes(i * 15);
    xs[i] = dtNow.ToOADate();
}

plt.PlotScatter(xs, ys);
plt.Ticks(dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss");
plt.Title("Time Axis Labels");

plt.SaveFig("Customize_Axis_TimeOnly.png");

自定义:轴-时间代码轴

轴刻度标签显示HH:MM:SS。SSS时间码(用于音频和视频编辑)

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

// simulate 10 seconds of audio data
int pointsPerSecond = 44100;
Random rand = new Random(0);
double[] ys = DataGen.RandomWalk(rand, pointsPerSecond * 10);

// For DateTime compatibility, sample rate must be points/day.
// Also, avoid negative dates by offsetting the plot by today's date.
double secondsPerDay = 24 * 60 * 60;
double pointsPerDay = secondsPerDay * pointsPerSecond;
double today = DateTime.Today.ToOADate();

plt.PlotSignal(ys, sampleRate: pointsPerDay, xOffset: today);
plt.Ticks(dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss.fff");

plt.SaveFig("Customize_Axis_TimeCodeAxis.png");

自定义:轴-十六进制轴

轴刻度标签可以位于任何基准,而不仅仅是基准10

// Code from /src/ScottPlot.Demo/Customize/Axis.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data
double[] xs = { 0 };
double[] valuesA = { 0x40000000 };
double[] valuesB = { 0x40100000 };
double[] valuesC = { 0xA0000000 };

// to simulate stacking B on A, shift B up by A
double[] valuesB2 = new double[valuesB.Length];
double[] valuesC2 = new double[valuesC.Length];
for (int i = 0; i < valuesB.Length; i++)
{
    valuesB2[i] = valuesA[i] + valuesB[i];
    valuesC2[i] = valuesC[i] + valuesB2[i];
}

// plot the bar charts in reverse order (highest first)
plt.PlotBar(xs, valuesC2, label: "Process C");
plt.PlotBar(xs, valuesB2, label: "Process B");
plt.PlotBar(xs, valuesA, label: "Process A");

// configure ticks for base 16 Y-axis
plt.Ticks(baseY: 16, prefixY: "0x");
plt.Axis(-1, 1, 0, 0x1A0000000);

// further customize the plot
plt.Ticks(displayTicksX: false, displayTicksY: true);
plt.Title("Memory Consumption");
plt.YLabel("Memory (Bytes)");
plt.Legend();

plt.SaveFig("Customize_Axis_HexadecimalAxis.png");

自定义:AxisLimits-自动适应数据

自动调整轴限制以适应数据。默认情况下,数据会略微填充额外的空间。

// Code from /src/ScottPlot.Demo/Customize/AxisLimits.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.AxisAuto();

plt.SaveFig("Customize_AxisLimits_Auto.png");

自定义:AxisLimits-具有指定边距的自动拟合

AxisAuto()参数允许用户定义每个轴的填充量(边距)。将边距设置为0将调整打印轴限制,以紧密配合数据。

// Code from /src/ScottPlot.Demo/Customize/AxisLimits.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.5);

plt.SaveFig("Customize_AxisLimits_AutoMargin.png");

自定义:轴限制-手动定义轴限制

用户可以手动定义轴限制。如果传入空值,则不调整轴限制。

// Code from /src/ScottPlot.Demo/Customize/AxisLimits.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Axis(-10, 60, -3, 3);

plt.SaveFig("Customize_AxisLimits_Manual.png");

自定义:AxisLimits-缩放

用户可以通过提供分数缩放量来轻松缩放。数字>1放大,而数字<1缩小。

// Code from /src/ScottPlot.Demo/Customize/AxisLimits.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.AxisZoom(1.5, 1.5);

plt.SaveFig("Customize_AxisLimits_Zoom.png");

定制:AxisLimits-Pan

用户可以轻松地在每个轴上平移定义的量。

// Code from /src/ScottPlot.Demo/Customize/AxisLimits.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.AxisPan(-10, .5);

plt.SaveFig("Customize_AxisLimits_Pan.png");

自定义:颜色-默认颜色集

默认颜色集与matplotlib使用的颜色集相同。

// Code from /src/ScottPlot.Demo/Customize/Colors.cs
var plt = new ScottPlot.Plot(600, 400);

plt.Title($"{plt.Colorset().Name} Colorset (Default)");

Random rand = new Random(0);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.AxisAuto(horizontalMargin: 0);

plt.SaveFig("Customize_Colors_DefaultColorset.png");

定制:颜色-Nord Colorset

使用Nord颜色的示例颜色集。

// Code from /src/ScottPlot.Demo/Customize/Colors.cs
var plt = new ScottPlot.Plot(600, 400);

plt.Colorset(Colorset.Nord);
plt.Title($"{plt.Colorset().Name} Colorset");

Random rand = new Random(0);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.AxisAuto(horizontalMargin: 0);

plt.SaveFig("Customize_Colors_NordColorset.png");

定制:颜色-深色配色

设计用于深色背景的颜色集示例。

// Code from /src/ScottPlot.Demo/Customize/Colors.cs
var plt = new ScottPlot.Plot(600, 400);

plt.Style(Style.Gray1);
plt.Colorset(Colorset.OneHalfDark);
plt.Title($"{plt.Colorset().Name} Colorset");

Random rand = new Random(0);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.PlotSignal(DataGen.RandomWalk(rand, 1000), lineWidth: 2);
plt.AxisAuto(horizontalMargin: 0);

plt.SaveFig("Customize_Colors_DarkColorset.png");

自定义:数字-背景色

图形和数据区背景色可以单独设置。

// Code from /src/ScottPlot.Demo/Customize/Figure.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(figBg: Color.LightBlue);
plt.Style(dataBg: Color.LightYellow);

plt.SaveFig("Customize_Figure_Background.png");

定制:图-角框

数据通常由一个框架(1px线)包围。可以使用参数自定义此框架。

// Code from /src/ScottPlot.Demo/Customize/Figure.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Frame(left: true, bottom: true, top: false, right: false);

plt.SaveFig("Customize_Figure_Frame.png");

自定义:数字-数字填充

如果需要,可以在数据区域周围添加额外的填充。

// Code from /src/ScottPlot.Demo/Customize/Figure.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

// custom colors are used to make it easier to see the data and figure areas
plt.Style(figBg: Color.LightBlue);
plt.Style(dataBg: Color.LightYellow);

plt.Layout(yScaleWidth: 80, titleHeight: 50, xLabelHeight: 20, y2LabelWidth: 20);

plt.SaveFig("Customize_Figure_FigurePadding.png");

自定义:数字-无填充

此示例显示如何仅打印数据区域(无轴标签、记号或记号标签)

// Code from /src/ScottPlot.Demo/Customize/Figure.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

// custom colors are used to make it easier to see the data and figure areas
plt.Style(figBg: Color.LightBlue);
plt.Style(dataBg: Color.LightYellow);

plt.Ticks(false, false);
plt.Frame(false);

// Eliminate space between the data area and frame edge by setting padding to 0.
// This must be repeated if the layout resets (such as when new items are added to the plot).
plt.TightenLayout(padding: 0);

plt.SaveFig("Customize_Figure_NoPad.png");

自定义:图形-抗锯齿

抗锯齿使绘图看起来更好,但会略微降低性能。图形的抗锯齿(包含标题、轴标签和轴标记)可以独立于数据区域和/或图例进行控制。

// Code from /src/ScottPlot.Demo/Customize/Figure.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin, label: "Sin");
plt.PlotScatter(x, cos, label: "Cos");

plt.Title("Plot Title");
plt.XLabel("Horizontal Axis");
plt.YLabel("Vertical Axis");
plt.Legend();

plt.AntiAlias(figure: false, data: false, legend: false);

// NOTE: anti-aliasing is automatically in the user control
// while the mouse button is held down to improve performance
// while panning and zooming. You can disable this feature by:
// formsPlot1.Configure(lowQualityWhileDragging = false);

plt.SaveFig("Customize_Figure_AntiAliasing.png");

自定义:网格-隐藏网格

Grid visibility(以及许多其他选项)在Grid()方法中作为参数提供。

// Code from /src/ScottPlot.Demo/Customize/Grid.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Grid(enable: false);

plt.SaveFig("Customize_Grid_Hide.png");

自定义:网格-网格线宽度

网格线宽度可以自定义。浮点值是可以接受的。

// Code from /src/ScottPlot.Demo/Customize/Grid.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Grid(lineWidth: 2);

plt.SaveFig("Customize_Grid_LineWidth.png");

自定义:网格-网格线样式

网格线样式可以自定义。

// Code from /src/ScottPlot.Demo/Customize/Grid.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Grid(lineStyle: ScottPlot.LineStyle.Dot);

plt.SaveFig("Customize_Grid_LineStyle.png");

自定义:栅格-定义的栅格间距

网格线之间的间距(与记号相同)可以手动定义。

// Code from /src/ScottPlot.Demo/Customize/Grid.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Grid(xSpacing: 2, ySpacing: .1);

plt.SaveFig("Customize_Grid_DefineSpacing.png");

定制:Legend-Legend演示

演示各种绘图类型在图例中的显示方式。

// Code from /src/ScottPlot.Demo/Customize/Legend.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);

plt.PlotErrorBars(
        xs: DataGen.Random(rand, 10, 10),
        ys: DataGen.Random(rand, 10, 10),
        xPositiveError: DataGen.Random(rand, 10),
        xNegativeError: DataGen.Random(rand, 10),
        yPositiveError: DataGen.Random(rand, 10),
        yNegativeError: DataGen.Random(rand, 10),
        label: "error bars"
    );

var func = new Func<double, double?>((x) => Math.Sin(x) * Math.Sin(10 * x) + 3);
plt.PlotFunction(func, label: "function", lineWidth: 2);

var func2 = new Func<double, double?>((x) => Math.Sin(x) * Math.Sin(10 * x) + 5);
plt.PlotFunction(func2, label: null); // null labels will not appear in legend

plt.PlotHLine(7.75, label: "horizontal line", lineStyle: LineStyle.Dot);
plt.PlotVLine(7.75, label: "vertical line", lineStyle: LineStyle.Dash);

plt.PlotHSpan(1.5, 2.5, label: "horizontal span");
plt.PlotVSpan(1.5, 2.5, label: "vertical span");

plt.PlotOHLC(new OHLC[]{
new OHLC(5, 6, 4, 5.5, 1),
new OHLC(6, 7.5, 3.5, 4.75, 1.5),
new OHLC(5.5, 6, 3, 4.5, 2)
});

plt.PlotCandlestick(new OHLC[]{
new OHLC(5, 6, 4, 5.5, 3),
new OHLC(6, 7.5, 3.5, 4.75, 3.5),
new OHLC(5.5, 6, 3, 4.5, 4)
});

plt.PlotScatter(
    xs: new double[] { 5, 5.5, 6, 7, 7, 6 },
    ys: new double[] { 7, 8, 7, 9, 7, 8 },
    lineStyle: LineStyle.Dash,
    lineWidth: 2,
    markerShape: MarkerShape.openCircle,
    markerSize: 10,
    label: "Scatter Plot"
    );

plt.PlotSignal(
    ys: DataGen.RandomNormal(rand, 10),
    sampleRate: 5,
    xOffset: 3,
    yOffset: 8,
    label: "Signal Plot"
    );

plt.PlotText("ScottPlot", 6, 6, rotation: 25, fontSize: 14, bold: true);

plt.PlotPoint(1, 9, label: "point");
plt.PlotArrow(8, 8, 8.5, 8.5, label: "arrow");

plt.Axis(0, 13, -1, 11);
plt.Legend();
plt.Grid(false);

plt.SaveFig("Customize_Legend_LegendDemo.png");

自定义:打印样式-打印后修改样式

最初打印数据时,样式通常定义为参数。但是,打印函数返回的对象包含打印后可以修改的样式信息。在某些情况下,这些属性允许比初始函数参数更广泛的自定义。

// Code from /src/ScottPlot.Demo/Customize/PlotStyle.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

var thing1 = plt.PlotScatter(x, sin, label: "thing 1");
var thing2 = plt.PlotScatter(x, cos, label: "thing 2");

thing1.lineWidth = 5;
thing1.markerShape = MarkerShape.openCircle;
thing1.markerSize = 20;

thing2.color = Color.Magenta;

plt.Legend();

plt.SaveFig("Customize_PlotStyle_ModifyAfterPlot.png");

自定义:PlotStyle-到处都有自定义字体

对多种类型的标签使用cutom字体、颜色和大小

// Code from /src/ScottPlot.Demo/Customize/PlotStyle.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Title("Impressive Graph", fontName: "courier new", fontSize: 24, color: Color.Purple, bold: true);
plt.YLabel("vertical units", fontName: "impact", fontSize: 24, color: Color.Red, bold: true);
plt.XLabel("horizontal units", fontName: "georgia", fontSize: 24, color: Color.Blue, bold: true);
plt.PlotText("very graph", 25, .8, fontName: "comic sans ms", fontSize: 24, color: Color.Blue, bold: true);
plt.PlotText("so data", 0, 0, fontName: "comic sans ms", fontSize: 42, color: Color.Magenta, bold: true);
plt.PlotText("many documentation", 3, -.6, fontName: "comic sans ms", fontSize: 18, color: Color.DarkCyan, bold: true);
plt.PlotText("wow.", 10, .6, fontName: "comic sans ms", fontSize: 36, color: Color.Green, bold: true);
plt.PlotText("NuGet", 32, 0, fontName: "comic sans ms", fontSize: 24, color: Color.Gold, bold: true);
plt.Legend(fontName: "comic sans ms", fontSize: 16, bold: true, fontColor: Color.DarkBlue);
plt.Ticks(fontName: "comic sans ms", fontSize: 12, color: Color.DarkBlue);

plt.SaveFig("Customize_PlotStyle_StyledLabels.png");

自定义:PlotStyle-图例

图例可用于显示使用“label”参数绘制的数据。Legend()的参数允许用户定义其位置。

// Code from /src/ScottPlot.Demo/Customize/PlotStyle.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin, label: "sin");
plt.PlotScatter(x, cos, label: "cos");
plt.Legend();

plt.SaveFig("Customize_PlotStyle_CustomLegend.png");

自定义:打印样式-打印样式(默认)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Default);

plt.SaveFig("Customize_PlotStyles_Default.png");

自定义:打印样式-打印样式(Seaborn)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Seaborn);

plt.SaveFig("Customize_PlotStyles_Seaborn.png");

自定义:打印样式-打印样式(控件)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Control);

plt.SaveFig("Customize_PlotStyles_Control.png");

自定义:打印样式-打印样式(蓝色1)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Blue1);

plt.SaveFig("Customize_PlotStyles_Blue1.png");

自定义:打印样式-打印样式(蓝色2)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Blue2);

plt.SaveFig("Customize_PlotStyles_Blue2.png");

自定义:打印样式-打印样式(蓝色3)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Blue3);

plt.SaveFig("Customize_PlotStyles_Blue3.png");

自定义:打印样式-打印样式(Light1)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Light1);

plt.SaveFig("Customize_PlotStyles_Light1.png");

自定义:打印样式-打印样式(Light2)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Light2);

plt.SaveFig("Customize_PlotStyles_Light2.png");

自定义:打印样式-打印样式(灰色1)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Gray1);

plt.SaveFig("Customize_PlotStyles_Gray1.png");

自定义:打印样式-打印样式(灰色2)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Gray2);

plt.SaveFig("Customize_PlotStyles_Gray2.png");

自定义:打印样式-打印样式(黑色)

没有提供描述。。。

// Code from /src/ScottPlot.Demo/Customize/PlotStyles.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Style(ScottPlot.Style.Black);

plt.SaveFig("Customize_PlotStyles_Black.png");

自定义:勾号-隐藏勾号标签

Tick标签的可见性可以通过Ticks()方法的参数来控制

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Ticks(displayTicksX: false);

plt.SaveFig("Customize_Ticks_Visibility.png");

自定义:记号-数字记号格式

可以使用数字格式字符串自定义数字记号的显示格式。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

// See https://tinyurl.com/y86clj9k to learn about numeric format strings
plt.Ticks(numericFormatStringX: "E2", numericFormatStringY: "P1");

plt.SaveFig("Customize_Ticks_Formatting.png");

自定义:刻度-日期时间轴

如果值(双[])是OATime值,则可以将轴刻度标签设置为显示日期和时间格式。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] temperature = DataGen.RandomWalk(rand, 60 * 8);
DateTime start = new DateTime(2019, 08, 25, 8, 30, 00);
double pointsPerDay = 24 * 60;

plt.PlotSignal(temperature, sampleRate: pointsPerDay, xOffset: start.ToOADate());
plt.Ticks(dateTimeX: true);
plt.YLabel("Temperature (C)");

plt.SaveFig("Customize_Ticks_DateAxis.png");

自定义:勾号-定义勾号位置

可以手动定义刻度位置和标签的数组。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

double[] xPositions = { 7, 21, 37, 46 };
string[] xLabels = { "VII", "XXI", "XXXVII", "XLVI" };
plt.XTicks(xPositions, xLabels);

double[] yPositions = { -1, 0, .5, 1 };
string[] yPabels = { "bottom", "center", "half", "top" };
plt.YTicks(yPositions, yPabels);

plt.SaveFig("Customize_Ticks_Positions.png");

自定义:刻度-非线性刻度间距

自定义记号标签以提供非线性轴外观

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

// these are our nonlinear data values we wish to plot
double[] amplitudes = { 23.9, 24.2, 24.3, 24.5, 25.3, 26.3, 27.6, 31.4, 33.7, 36,
                        38.4, 42, 43.5, 46.1, 48.8, 51.5, 53.2, 55, 56.9, 58.7, 60.6 };
double[] frequencies = { 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630,
                         800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000 };

// ignore the "real" X values and plot data at consecutive X values (0, 1, 2, 3...)
double[] positions = DataGen.Consecutive(frequencies.Length);
plt.PlotScatter(positions, amplitudes);

// then define tick labels based on "real" X values, rotate them, and give them extra space
string[] labels = frequencies.Select(x => x.ToString()).ToArray();
plt.XTicks(positions, labels);
plt.Ticks(xTickRotation: 45);

// apply axis labels, trigging a layout reset
plt.Title("Vibrational Coupling");
plt.YLabel("Amplitude (dB)");
plt.XLabel("Frequency (Hz)");

// manually tweak the layout to add extra padding for rotated labels
plt.Layout(xScaleHeight: 30);

plt.SaveFig("Customize_Ticks_NonlinearTickSpacing.png");

自定义:滴答声-滴答声递减

ScottPlot将始终显示X值从左向右递增的数据。要模拟反转轴(数字从左向右递减)在负空间中打印数据,请使用Tick()参数反转Tick标签的符号。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

// plot in the negative space
plt.PlotSignal(DataGen.Sin(50), xOffset: -50);

// then invert the sign of the axis tick labels
plt.Ticks(invertSignX: true);
plt.Ticks(invertSignY: true);

plt.SaveFig("Customize_Ticks_Inverted.png");

自定义:记号-定义的记号间距

勾号之间的间距可以通过设置栅格间距手动定义。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

plt.Grid(xSpacing: 2, ySpacing: .1);

plt.SaveFig("Customize_Ticks_DefineSpacing.png");

自定义:记号-本地化格式(匈牙利语)

对于不同的文化,大量的数字和日期的格式是不同的。匈牙利语就是一个很好的例子:他们用空格分隔大数字,用句点分隔日期中的字段。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

// generate some data
Random rand = new Random(0);
double[] price = ScottPlot.DataGen.RandomWalk(rand, 60 * 8, 10000);
DateTime start = new DateTime(2019, 08, 25, 8, 30, 00);
double pointsPerDay = 24 * 60;

// create the plot
plt.PlotSignal(price, sampleRate: pointsPerDay, xOffset: start.ToOADate());
plt.Ticks(dateTimeX: true);
plt.YLabel("Price");
plt.XLabel("Date and Time");
plt.Title("Hungarian Formatted DateTime Tick Labels");

// set the localization
var culture = System.Globalization.CultureInfo.CreateSpecificCulture("hu"); // Hungarian
plt.SetCulture(culture);

plt.SaveFig("Customize_Ticks_LocalizedHungarian.png");

自定义:刻度-本地化格式(德语)

对于不同的文化,大量的数字和日期的格式是不同的。德语就是一个很好的例子:他们用句点分隔大数字,用句点分隔日期中的字段。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

// generate some data
Random rand = new Random(0);
double[] price = ScottPlot.DataGen.RandomWalk(rand, 60 * 8, 10000);
DateTime start = new DateTime(2019, 08, 25, 8, 30, 00);
double pointsPerDay = 24 * 60;

// create the plot
plt.PlotSignal(price, sampleRate: pointsPerDay, xOffset: start.ToOADate());
plt.Ticks(dateTimeX: true);
plt.YLabel("Price");
plt.XLabel("Date and Time");
plt.Title("German Formatted DateTime Tick Labels");

// set the localization
var culture = System.Globalization.CultureInfo.CreateSpecificCulture("de"); // German
plt.SetCulture(culture);

plt.SaveFig("Customize_Ticks_LocalizedGerman.png");

自定义:记号-使用自定义区域性设置记号的格式

SetCulture()作为参数,允许用户手动定义格式化字符串,这些字符串将全局用于更改数字和日期的格式化方式。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

// generate 10 days of data
int pointCount = 10;
double[] values = DataGen.RandomWalk(null, pointCount);
double[] days = new double[pointCount];
DateTime day1 = new DateTime(1985, 09, 24);
for (int i = 0; i < days.Length; i++)
    days[i] = day1.AddDays(1).AddDays(i).ToOADate();

// plot the data with custom tick format (https://tinyurl.com/ycwh45af)
plt.PlotScatter(days, values);
plt.Ticks(dateTimeX: true);
plt.SetCulture(shortDatePattern: "M\\/dd");

plt.SaveFig("Customize_Ticks_CustomCulture.png");

定制:蜱虫-容纳大蜱虫

打印布局会自动调整,以适应大刻度标签。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

// generate LARGE data
Random rand = new Random(0);
double[] xs = ScottPlot.DataGen.Consecutive(100);
double[] ys = ScottPlot.DataGen.RandomWalk(rand, 100, 1e2, 1e15);
plt.PlotScatter(xs, ys);
plt.YLabel("vertical units");
plt.XLabel("horizontal units");

plt.SaveFig("Customize_Ticks_Large.png");

自定义:滴答声-倍增符号

为了保持刻度标签较小,当其值较大时,可以使用“倍增”符号。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 100;
double[] largeXs = DataGen.Consecutive(pointCount, spacing: 1e6);
double[] largeYs = DataGen.Random(rand, pointCount, multiplier: 1e6);

plt.PlotScatter(largeXs, largeYs);
plt.Ticks(useMultiplierNotation: true);

plt.SaveFig("Customize_Ticks_MultiplierNotation.png");

自定义:刻度-偏移符号

当刻度标签的值远离零时,可以使用小的“偏移”符号来保持刻度标签。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
int pointCount = 100;
double[] largeXs = DataGen.Consecutive(pointCount, offset: 1e6);
double[] largeYs = DataGen.Random(rand, pointCount, offset: 1e6);

plt.PlotScatter(largeXs, largeYs);
plt.Ticks(useOffsetNotation: true);

plt.SaveFig("Customize_Ticks_OffsetNotation.png");

自定义:刻度-旋转的刻度

水平刻度可以旋转任意数量。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 51;
double[] x = DataGen.Consecutive(pointCount);
double[] sin = DataGen.Sin(pointCount);
double[] cos = DataGen.Cos(pointCount);

plt.PlotScatter(x, sin);
plt.PlotScatter(x, cos);

// setting the axis label resets the layout so call this first
plt.XLabel("Horizontal Axis Label");

// define axis tick rotation and tweak the layout to provide extra padding
plt.Ticks(xTickRotation: 45);

plt.SaveFig("Customize_Ticks_RotatedTicks.png");

自定义:刻度-定义的日期时间刻度间距

本例显示了如何使用固定的勾号间距。

// Code from /src/ScottPlot.Demo/Customize/Ticks.cs
var plt = new ScottPlot.Plot(600, 400);

int pointCount = 20;

// create a series of dates
double[] dates = new double[pointCount];
var firstDay = new DateTime(2020, 1, 22);
for (int i = 0; i < pointCount; i++)
    dates[i] = firstDay.AddDays(i).ToOADate();

// simulate data for each date
double[] values = new double[pointCount];
Random rand = new Random(0);
for (int i = 1; i < pointCount; i++)
    values[i] = values[i - 1] + rand.NextDouble();

plt.PlotScatter(dates, values);
plt.Ticks(dateTimeX: true);

// define tick spacing as 1 day (every day will be shown)
plt.Grid(xSpacing: 1, xSpacingDateTimeUnit: Config.DateTimeUnit.Day);
plt.Ticks(dateTimeX: true, xTickRotation: 45);
plt.Layout(xScaleHeight: 60);

plt.SaveFig("Customize_Ticks_DateAxisFixedSpace.png");

先进的

高级:条形图-多条形图

通过调整两个单独条形图的宽度和偏移量,可以同时显示多个条形图。但是,在大多数情况下,这是不必要的,因为PlotBar()和PlotPopulation()工具非常强大(请参见这些示例)。

// Code from /src/ScottPlot.Demo/Advanced/Bar.cs
var plt = new ScottPlot.Plot(600, 400);

// generate random data to plot
Random rand = new Random(0);
int pointCount = 10;
double[] xs = DataGen.Consecutive(pointCount);
double[] ys1 = DataGen.RandomNormal(rand, pointCount, 20, 5);
double[] ys2 = DataGen.RandomNormal(rand, pointCount, 20, 5);
double[] err1 = DataGen.RandomNormal(rand, pointCount, 5, 2);
double[] err2 = DataGen.RandomNormal(rand, pointCount, 5, 2);

// add both bar plots with a careful widths and offsets
plt.PlotBar(xs, ys1, err1, "data A", barWidth: .3, xOffset: -.2);
plt.PlotBar(xs, ys2, err2, "data B", barWidth: .3, xOffset: .2);

// customize the plot to make it look nicer
plt.Axis(y1: 0);
plt.Grid(enableVertical: false, lineStyle: LineStyle.Dot);
plt.Axis(y1: 0);
plt.Legend(location: legendLocation.upperRight);

// apply custom axis tick labels
string[] labels = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
plt.XTicks(xs, labels);

plt.SaveFig("Advanced_Bar_MultipleBars.png");

高级:多点-多点快速入门

多批次是包含多个子批次的单个图像。

// Code from /src/ScottPlot.Demo/Advanced/Multiplot.cs
Random rand = new Random(0);

var mp = new MultiPlot(width: width, height: height, rows: 2, cols: 2);
mp.GetSubplot(0, 0).PlotSignal(DataGen.Sin(50));
mp.GetSubplot(0, 1).PlotSignal(DataGen.Cos(50));
mp.GetSubplot(1, 0).PlotSignal(DataGen.Random(rand, 50));
mp.GetSubplot(1, 1).PlotSignal(DataGen.RandomWalk(rand, 50));

mp.SaveFig("Advanced_Multiplot_Quickstart.png");

高级:多点-匹配子地块轴

一个子地块的轴和布局信息可应用于另一个子地块。

// Code from /src/ScottPlot.Demo/Advanced/Multiplot.cs
Random rand = new Random(0);

var mp = new MultiPlot(width: width, height: height, rows: 2, cols: 2);
mp.GetSubplot(0, 0).PlotSignal(DataGen.Sin(50));
mp.GetSubplot(0, 1).PlotSignal(DataGen.Cos(50));
mp.GetSubplot(1, 0).PlotSignal(DataGen.Random(rand, 50));
mp.GetSubplot(1, 1).PlotSignal(DataGen.RandomWalk(rand, 50));

// adjust the bottom left plot to match the bottom right plot
var plotToAdjust = mp.GetSubplot(1, 0);
var plotReference = mp.GetSubplot(1, 1);
plotToAdjust.MatchAxis(plotReference);
plotToAdjust.MatchLayout(plotReference);

mp.SaveFig("Advanced_Multiplot_MatchAxis.png");

高级:统计-直方图

此示例演示如何绘制数据集的直方图。

// Code from /src/ScottPlot.Demo/Advanced/Statistics.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
double[] values = DataGen.RandomNormal(rand, pointCount: 1000, mean: 50, stdDev: 20);
var hist = new ScottPlot.Statistics.Histogram(values, min: 0, max: 100);

double barWidth = hist.binSize * 1.2; // slightly over-side to reduce anti-alias rendering artifacts

plt.PlotBar(hist.bins, hist.countsFrac, barWidth: barWidth, outlineWidth: 0);
plt.PlotScatter(hist.bins, hist.countsFracCurve, markerSize: 0, lineWidth: 2, color: Color.Black);
plt.Title("Normal Random Data");
plt.YLabel("Frequency (fraction)");
plt.XLabel("Value (units)");
plt.Axis(null, null, 0, null);
plt.Grid(lineStyle: LineStyle.Dot);

plt.SaveFig("Advanced_Statistics_Histogram.png");

高级:统计学-CPH

本例演示了如何绘制累积概率直方图(CPH)来比较两个数据集的分布。

// Code from /src/ScottPlot.Demo/Advanced/Statistics.cs
var plt = new ScottPlot.Plot(600, 400);

// create sample data for two datasets
Random rand = new Random(0);
double[] values1 = DataGen.RandomNormal(rand, pointCount: 1000, mean: 50, stdDev: 20);
double[] values2 = DataGen.RandomNormal(rand, pointCount: 1000, mean: 45, stdDev: 25);
var hist1 = new ScottPlot.Statistics.Histogram(values1, min: 0, max: 100);
var hist2 = new ScottPlot.Statistics.Histogram(values2, min: 0, max: 100);

// display datasets as step plots
plt.Title("Cumulative Probability Histogram");
plt.YLabel("Probability (fraction)");
plt.XLabel("Value (units)");
plt.PlotStep(hist1.bins, hist1.cumulativeFrac, lineWidth: 1.5, label: "sample A");
plt.PlotStep(hist2.bins, hist2.cumulativeFrac, lineWidth: 1.5, label: "sample B");
plt.Legend();
plt.Axis(null, null, 0, 1);
plt.Grid(lineStyle: LineStyle.Dot);

plt.SaveFig("Advanced_Statistics_CPH.png");

高级:统计学-线性回归

此示例演示如何为X/Y数据创建线性回归线。

// Code from /src/ScottPlot.Demo/Advanced/Statistics.cs
var plt = new ScottPlot.Plot(600, 400);

// Create some linear but noisy data
Random rand = new Random(0);
double[] ys = ScottPlot.DataGen.NoisyLinear(rand, pointCount: 100, noise: 30);
double[] xs = ScottPlot.DataGen.Consecutive(ys.Length);
double x1 = xs[0];
double x2 = xs[xs.Length - 1];

// use the linear regression fitter to fit these data
var model = new ScottPlot.Statistics.LinearRegressionLine(xs, ys);

// plot the original data and add the regression line
plt.Title($"Y = {model.slope:0.0000}x + {model.offset:0.0}\nR² = {model.rSquared:0.0000}");
plt.PlotScatter(xs, ys, lineWidth: 0);
plt.PlotLine(model.slope, model.offset, (x1, x2), lineWidth: 2);

plt.SaveFig("Advanced_Statistics_LinReg.png");

高级:统计-人口统计

人口类使人口统计工作变得容易。用双值数组实例化Population类,然后根据需要访问其属性和方法。

// Code from /src/ScottPlot.Demo/Advanced/Statistics.cs
var plt = new ScottPlot.Plot(600, 400);

// create some sample data to represent test scores
Random rand = new Random(0);
double[] scores = DataGen.RandomNormal(rand, 250, 85, 5);

// create a Population object from the data
var pop = new ScottPlot.Statistics.Population(scores);

// display the original values scattered vertically
double[] ys = DataGen.RandomNormal(rand, pop.values.Length, stdDev: .15);
plt.PlotScatter(pop.values, ys, markerSize: 10,
    markerShape: MarkerShape.openCircle, lineWidth: 0);

// display the bell curve for this distribution
double[] curveXs = DataGen.Range(pop.minus3stDev, pop.plus3stDev, .1);
double[] curveYs = pop.GetDistribution(curveXs, normalize: false);
plt.PlotScatter(curveXs, curveYs, markerSize: 0, lineWidth: 2);

// improve the style of the plot
plt.Title($"Test Scores (mean: {pop.mean:0.00} +/- {pop.stDev:0.00}, n={pop.n})");
plt.XLabel("Score");
plt.Grid(lineStyle: LineStyle.Dot);

plt.SaveFig("Advanced_Statistics_Population.png");

高级:统计学-样条插值

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

// Code from /src/ScottPlot.Demo/Advanced/Statistics.cs
var plt = new ScottPlot.Plot(600, 400);

// create a small number of X/Y data points and display them
double[] xs = { 0, 10, 20, 30 };
double[] ys = { 65, 25, 55, 80 };
plt.PlotScatter(xs, ys, Color.Black, markerSize: 10, lineWidth: 0, label: "Original Data");

// Calculate the interpolated splines using three different methods:
//   Natural splines are "stiffer" than a polynomial interpolations and are less likely to oscillate.
//   Periodic splines are natural splines whose first and last point slopes are matched.
//   End slope splines let you define first and last data point slopes (defaults to zero).
var nsi = new ScottPlot.Statistics.Interpolation.NaturalSpline(xs, ys, resolution: 20);
var psi = new ScottPlot.Statistics.Interpolation.PeriodicSpline(xs, ys, resolution: 20);
var esi = new ScottPlot.Statistics.Interpolation.EndSlopeSpline(xs, ys, resolution: 20);

// plot the interpolated Xs and Ys
plt.PlotScatter(nsi.interpolatedXs, nsi.interpolatedYs, Color.Red, markerSize: 3, label: "Natural Spline");
plt.PlotScatter(psi.interpolatedXs, psi.interpolatedYs, Color.Green, markerSize: 3, label: "Periodic Spline");
plt.PlotScatter(esi.interpolatedXs, esi.interpolatedYs, Color.Blue, markerSize: 3, label: "End Slope Spline");

plt.Legend();

plt.SaveFig("Advanced_Statistics_SplineInterpolation.png");

实验的

实验:CustomPlottables-手动添加一个Plottable

演示如何在不依赖绘图模块中的方法的情况下向绘图中添加绘图表。

// Code from /src/ScottPlot.Demo/Experimental/CustomPlottables.cs
var plt = new ScottPlot.Plot(600, 400);

// rather than call Plot.PlotText(), create the Plottable manually
var customPlottable = new PlottableText()
{
    text = "test",
    x = 2,
    y = 3,
    FontColor = System.Drawing.Color.Magenta,
    FontName = "arial",
    FontSize = 26,
    FontBold = true,
    alignment = TextAlignment.middleCenter,
    rotation = 0,
    frame = false,
    frameColor = System.Drawing.Color.Green
};

// you can access properties which may not be exposed by a Plot method
customPlottable.rotation = 45;

// add the custom plottable to the list of plottables like this
List<Plottable> plottables = plt.GetPlottables();
plottables.Add(customPlottable);

plt.SaveFig("Experimental_CustomPlottables_AddPlottable.png");

实验性:FringeCase-空图

如果从未添加绘图表,则绘图就是这样的。

// Code from /src/ScottPlot.Demo/Experimental/FringeCase.cs
var plt = new ScottPlot.Plot(600, 400);

plt.Title("Empty Plot");

plt.SaveFig("Experimental_FringeCase_EmptyPlot.png");

实验:热图-热图快速入门

热图是显示强度数据的好方法。

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

double[,] imageData = { { 1, 2, 3 },
                        { 4, 5, 6 } };

plt.PlotHeatmap(imageData);

plt.SaveFig("Experimental_Heatmap_HeatmapQuickstart.png");

实验:热图-2D波形

另一个热图例子。

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

int[] xs = Enumerable.Range(0, 100).ToArray();
int[] ys = Enumerable.Range(0, 100).ToArray();

double[,] intensities = new double[ys.Length, xs.Length];
for (int i = 0; i < ys.Length; i++)
{
    for (int j = 0; j < xs.Length; j++)
    {
        intensities[i, j] = (Math.Sin(i * .2) + Math.Cos(j * .2)) * 100;
    }
}

plt.PlotHeatmap(intensities);

plt.SaveFig("Experimental_Heatmap_HeatmapSinCos.png");

实验:热图-自定义热图

热图有很多定制选项

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random();
int[] xs = Enumerable.Range(0, 100).ToArray();
int[] ys = Enumerable.Range(0, 100).ToArray();

double[,] intensities = new double[ys.Length, xs.Length];

for (int i = 0; i < ys.Length; i++)
{
    for (int j = 0; j < xs.Length; j++)
    {
        intensities[i, j] = (Math.Sin(i * .2) + Math.Cos(j * .2)) * 100;
    }
}

//Change the color map to turbo, and renumber the axes
plt.PlotHeatmap(intensities, Colormap.Turbo, axisOffsets: new double[] { -5, -5 }, axisMultipliers: new double[] { 10, 10 });

plt.SaveFig("Experimental_Heatmap_HeatmapCustomizability.png");

实验:热图-自定义比例

热图有很多定制选项

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random();
int[] xs = Enumerable.Range(0, 100).ToArray();
int[] ys = Enumerable.Range(0, 100).ToArray();

double[,] intensities = new double[ys.Length, xs.Length];

for (int i = 0; i < ys.Length; i++)
{
    for (int j = 0; j < xs.Length; j++)
    {
        intensities[i, j] = (Math.Sin(i * .2) + Math.Cos(j * .2)) * 100;
    }
}

//You'll notice these are the same settings as the previous demo, except the axis scale is noticably different
plt.PlotHeatmap(intensities, Colormap.Turbo, axisOffsets: new double[] { -5, -5 }, axisMultipliers: new double[] { 10, 10 }, scaleMin: -150, scaleMax: 300);

plt.SaveFig("Experimental_Heatmap_HeatmapCustomScale.png");

实验:热图-XY数据的热图(高斯)

用于显示点簇

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
//Some noisy data centred around the middle
int[] xs = DataGen.RandomNormal(rand, 10000, 25, 10).Select(x => (int)x).ToArray();
int[] ys = DataGen.RandomNormal(rand, 10000, 25, 10).Select(y => (int)y).ToArray();

//Standard Deviation of 4
double[,] intensities = Tools.XYToIntensities(Tools.IntensityMode.gaussian, xs, ys, 50, 50, 4);
plt.PlotHeatmap(intensities);

plt.SaveFig("Experimental_Heatmap_HeatmapFromXYGaussian.png");

实验:热图-XY数据的热图(密度)

用于显示点簇

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

Random rand = new Random(0);
//Some noisy data centred around the middle
int[] xs = DataGen.RandomNormal(rand, 10000, 25, 10).Select(x => (int)x).ToArray();
int[] ys = DataGen.RandomNormal(rand, 10000, 25, 10).Select(y => (int)y).ToArray();

//Each cell is a square with side-length of 4
double[,] intensities = Tools.XYToIntensities(Tools.IntensityMode.density, xs, ys, 50, 50, 4);
plt.PlotHeatmap(intensities);

plt.SaveFig("Experimental_Heatmap_HeatmapFromXYDensity.png");

实验:热图-热图图像

使用热图显示的示例图像

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

double[,] imageData = DataGen.SampleImageData();
plt.PlotHeatmap(imageData);

plt.SaveFig("Experimental_Heatmap_HeatmapImage.png");

实验:热图-热图背景图像

低于阈值的热图值可以替换为位图图像。

// Code from /src/ScottPlot.Demo/Experimental/Heatmap.cs
var plt = new ScottPlot.Plot(600, 400);

double[,] imageData = DataGen.SampleImageData();

//This could be applied more usefully to an image pertinent to the data
//For example a map of the world, if your data is about geographic phenomenon
Bitmap background = DataGen.SampleImage();

plt.PlotHeatmap(imageData, transparencyThreshold: 20, backgroundImage: background);

plt.SaveFig("Experimental_Heatmap_BackGroundImage.png");