I ran into a problem that I wouldn't have even noticed had I not been trying to use a LogAxis as the Y Axis on a plot.
myPlotSurface.YAxis1 = new LogAxis(myLinePlot.SuggestYAxis)
When I then tried to refresh my plot, it would fail saying I can't have negative data on a log axis, but of course I didn't have any negative data.
Looking at the SequenceAdapter code in SVN, which I've trimmed a little just to get the relevant parts:
public Axis SuggestXAxis()
{
Axis a = this.XAxisSuggester_.Get();
// The world length should never be returned as 0
// This would result in an axis with a span of 0 units
// which can not be properly displayed.
if (a.WorldLength == 0.0)
{
a.IncreaseRange(0.08);
}
return a;
}
public Axis SuggestYAxis()
{
Axis a = this.YAxisSuggester_.Get();
a.IncreaseRange(0.08);
return a;
}
Basically, what occurs is on the X axis, the range is only increased if the returned axis was zero, but on the Y axis, it is always increased by +/- 8% of the range. If your span is sufficiently large enough, and your lower limit close enough to zero, the range can get extended negative.
There may be a reason I don't know about, but if there isn't, I would suggest making the Y axis behave in the same manner as the X axis.
--matt
Logged In: YES
user_id=2104277
Originator: NO
I ran into this same problem. Here's a quick code sample that generates the error:
NPlot.Bitmap.PlotSurface2D plot = new NPlot.Bitmap.PlotSurface2D(1000, 1000);
LogAxis verticalAxis = new LogAxis();
plot.YAxis1 = verticalAxis;
System.Collections.ArrayList yvalues = new System.Collections.ArrayList();
yvalues.Add(1);
yvalues.Add(1000000);
System.Collections.ArrayList xvalues = new System.Collections.ArrayList();
xvalues.Add(0);
xvalues.Add(1);
LinePlot linePlot = new LinePlot(yvalues, xvalues);
plot.Add(linePlot);
A workaround to this issue is to add the lineplot first, and then the log axis.
The problem is because the yaxis range is increased by 8%, and then that new range is passed to the "LUB" method of the log axis, which complains because the lower bound of the "suggested" axis is negative. I'm not familiar enough with the code to know what the best way to fix this might be. I don't think it would be to remove the 8% range increase altogether, I assume that is done for display reasons, so that the data doesn't go right up against the top and bottom of the graph.