-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Labels
BUGunexpected behaviorunexpected behavior
Description
Describe the bug
If you attempt to use a ScottPlot.Tools.Log10 on a dataset which contains 0, it will appear to work properly. However, Math.Log10(0) returns double.NegativeInfinity, which does not play nicely with Plottable.GetLimits(). It causes the axis to return limits of [double.NaN, double.NaN]. This does not cause a crash, but simply for the plot to not draw.
To Reproduce
Use ScottPlot.Tools.Log10 on a dataset which contains 0.
I modified the Log Axis demo to look like this:
public class LogAxis : PlotDemo, IPlotDemo
{
public string name { get; } = "Log Axis";
public string description { get; } = "";
public void Render(Plot plt)
{
// 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;
}
dataYs[0] = 0;
// this tool can convert linear data to log data
double[] dataYsLog = ScottPlot.Tools.Log10(dataYs);
foreach(double curr in dataYsLog) {
Debug.WriteLine(curr);
}
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");
}
}Screenshots
If applicable, add screenshots to help explain your problem
Output for given code:
Debug output: https://pastebin.com/9vYd9Hdm
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BUGunexpected behaviorunexpected behavior
