Skip to content

Commit ba33f83

Browse files
authored
Cookbook: add recipe for drawing a line for a polar axis plot (ScottPlot#5019)
1 parent 87e5471 commit ba33f83

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

  • src/ScottPlot5/ScottPlot5 Cookbook/Recipes/PlotTypes

src/ScottPlot5/ScottPlot5 Cookbook/Recipes/PlotTypes/PolarAxis.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
namespace ScottPlotCookbook.Recipes.PlotTypes;
2-
32
public class PolarAxis : ICategory
43
{
54
public Chapter Chapter => Chapter.PlotTypes;
@@ -278,4 +277,40 @@ public override void Execute()
278277
}
279278
}
280279
}
280+
281+
public class PolarWithLines : RecipeBase
282+
{
283+
public override string Name => "Polar Axis with Lines";
284+
public override string Description => "This is an example of a polar axis with lines instead of points";
285+
286+
[Test]
287+
public override void Execute()
288+
{
289+
// add a polar axis to the plot
290+
var polarAxis = myPlot.Add.PolarAxis(radius: 100);
291+
292+
IColormap colormap = new ScottPlot.Colormaps.Turbo();
293+
Coordinates? previousPt = null;
294+
295+
foreach (double fraction in ScottPlot.Generate.Range(0, 1, 0.02))
296+
{
297+
// use the polar axis to get X/Y coordinates given a position in polar space
298+
double radius = 100 * fraction;
299+
double degrees = 360 * fraction;
300+
Coordinates pt = polarAxis.GetCoordinates(radius, degrees);
301+
302+
if (previousPt != null)
303+
{
304+
ScottPlot.Plottables.LinePlot lp = myPlot.Add.Line(previousPt.Value.X, previousPt.Value.Y, pt.X, pt.Y);
305+
lp.LineWidth = 5;
306+
lp.Color = Colors.Red;
307+
previousPt = pt;
308+
}
309+
else
310+
{
311+
previousPt = pt;
312+
}
313+
}
314+
}
315+
}
281316
}

0 commit comments

Comments
 (0)