Skip to content

Commit

Permalink
refine polygon demo #255
Browse files Browse the repository at this point in the history
  • Loading branch information
swharden committed Apr 5, 2020
1 parent 5a225d9 commit 40d6d22
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ScottPlot.Demo/PlotTypes/Polygon.cs
Expand Up @@ -44,15 +44,14 @@ public void Render(Plot plt)
var dataX = DataGen.Consecutive(dataY.Length, spacing: 0.025);

// create an array with an extra point on each side of the data
double baseline = 0;
var xs = new double[dataX.Length + 2];
var ys = new double[dataY.Length + 2];
Array.Copy(dataX, 0, xs, 1, dataX.Length);
Array.Copy(dataY, 0, ys, 1, dataY.Length);
xs[0] = dataX[0];
xs[xs.Length - 1] = dataX[dataX.Length - 1];
ys[0] = baseline;
ys[ys.Length - 1] = baseline;
ys[0] = 0;
ys[ys.Length - 1] = 0;

// separate the data into two arrays (for positive and negative)
double[] neg = new double[ys.Length];
Expand All @@ -71,6 +70,7 @@ public void Render(Plot plt)
plt.PlotPolygon(xs, pos, "positive", lineWidth: 1,
lineColor: Color.Black, fillColor: Color.Green, fillAlpha: .5);
plt.Title("Shaded Line Plot (negative vs. positive)");
plt.Legend(location: ScottPlot.legendLocation.lowerLeft);
plt.AxisAuto(0);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/PlotTypes/Polygon.cs
Expand Up @@ -82,6 +82,7 @@ public void Test_PlotPolygon_SimulateShadedCurve()
plt.PlotPolygon(arrX, arrY, lineWidth: 1, lineColor: Color.Black, fillAlpha: .5);

plt.Title("Shaded Line Plot");
plt.Legend(location: ScottPlot.legendLocation.lowerLeft);
TestTools.SaveFig(plt);
}

Expand Down

0 comments on commit 40d6d22

Please sign in to comment.