Skip to content

PlotScatter fails plotting a single point #126

@bonzaiferroni

Description

@bonzaiferroni

I discovered that an exception will be thrown if using PlotScatter with just a single point, when the line width is greater than 0. I'm using version 3.1.3 in .NET 4.7.1.

Here is the stacktrace:

System.ArgumentException: Parameter is not valid.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawLines(Pen pen, PointF[] points)
   at ScottPlot.PlottableScatter.Render(Settings settings)
   at ScottPlot.Renderer.DataPlottables(Settings settings)
   at ScottPlot.Plot.RenderBitmap()
   at ScottPlot.Plot.SaveFig(String filePath, Boolean renderFirst)

This code will reproduce the exception:

var chart = new Plot();
chart.PlotScatter(new [] {1d}, new [] {1d}, lineWidth: 1);
chart.SaveFig("Chart.png");

Perhaps this condition added to PlottableScatter.cs#205 would fix the issue:

            if (penLine.Width > 0 && points.Length > 1)
            {
                if (stepDisplay)
                    settings.gfxData.DrawLines(penLine, pointsStep);
                else
                    settings.gfxData.DrawLines(penLine, points);
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions