绘图仪:填充
 

曲线下填充

填充方法有助于创建半透明多边形,以填充曲线下的区域。这可用于在散点图下显示着色效果,即使此处创建的绘图仪是具有可选边颜色和填充颜色的多边形。

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

// create sample data
double[] xs = DataGen.Range(0, 10, .1, true);
double[] ys1 = DataGen.Sin(xs);
double[] ys2 = DataGen.Cos(xs);

// add filled polygons
plt.AddFill(xs, ys1);
plt.AddFill(xs, ys2, baseline: -.25);

// tighten the axis limits so we don't see lines on the edges
plt.SetAxisLimits(xMin: 0, xMax: 10);

plt.SaveFig("fill_curve.png");
 

填上填下

有时,您希望共享曲线下的区域,但根据基线值的哪一侧更改其颜色。有一个助手方法可以让这更容易。

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

// create sample data
Random rand = new Random(3);
double[] xs = DataGen.Consecutive(201);
double[] ys = DataGen.RandomWalk(rand, xs.Length);

// add filled polygons
plt.AddFillAboveAndBelow(xs, ys);

// tighten the axis limits so we don't see lines on the edges
plt.SetAxisLimits(xMin: 0, xMax: 200);

plt.SaveFig("fill_aboveBelow.png");
 

曲线间填充

给定两条曲线,可以创建一个多边形,以呈现它们之间的着色外观。这里我们将显示两个散点图,然后创建一个多边形来填充它们之间的区域。

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

// create sample data
double[] xs = DataGen.Range(0, 10, .1, true);
double[] ys1 = DataGen.Sin(xs);
double[] ys2 = DataGen.Cos(xs);

// add a polygon to fill the region between the two curves
plt.AddFill(xs, ys1, xs, ys2);

// add two scatter plots the traditional way
plt.AddScatter(xs, ys1, color: Color.Black);
plt.AddScatter(xs, ys2, color: Color.Black);

// tighten the axis limits so we don't see lines on the edges
plt.SetAxisLimits(xMin: 0, xMax: 10);

plt.SaveFig("fill_between.png");
 

阴影填充

当存在重叠填充时,阴影填充很有用,例如此图描绘了价格下限下可能的生产者盈余范围。

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

double SupplyFunction(double q) => 5 * q + 1;
double DemandFunction(double q) => -3 * q + 17;

const double priceFloor = 12.5;
double[] xs = DataGen.Consecutive(5);
double[] supply = xs.Select(SupplyFunction).ToArray();
double[] demand = xs.Select(DemandFunction).ToArray();

plt.AddScatter(xs, supply, markerShape: MarkerShape.none, label: "Supply");
plt.AddScatter(xs, demand, markerShape: MarkerShape.none, label: "Demand");
plt.AddHorizontalLine(priceFloor, label: "Price Floor");

double[] maxProducerSurplusBounds = new double[] { 0, 1.5 };
var maxProducerSurplus = plt.AddFill(maxProducerSurplusBounds, maxProducerSurplusBounds.Select(SupplyFunction).ToArray(), maxProducerSurplusBounds, Enumerable.Repeat(priceFloor, 2).ToArray());
maxProducerSurplus.LineWidth = 0;
maxProducerSurplus.FillColor = Color.LawnGreen;
maxProducerSurplus.HatchColor = Color.Transparent;
maxProducerSurplus.HatchStyle = Drawing.HatchStyle.StripedWideDownwardDiagonal;
maxProducerSurplus.Label = "Maximum Possible Producer Surplus";

double[] minProducerSurplusBounds = new double[] { 1.2, 2.3 };
var minProducerSurplus = plt.AddFill(minProducerSurplusBounds, minProducerSurplusBounds.Select(SupplyFunction).ToArray(), minProducerSurplusBounds, Enumerable.Repeat(priceFloor, 2).ToArray());
minProducerSurplus.LineWidth = 0;
minProducerSurplus.FillColor = Color.Transparent;
minProducerSurplus.HatchColor = Color.Red;
minProducerSurplus.HatchStyle = Drawing.HatchStyle.StripedWideDownwardDiagonal;
minProducerSurplus.Label = "Minimum Possible Producer Surplus";

plt.Legend();

plt.SaveFig("fill_hatched.png");