Profile Picture

Logarithmic scale with zeros

Posted By Fredrik Östlund 14 Years Ago
Author
Message
Fredrik Östlund
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 4, Visits: 1
Hi,

I need to plot data in log scale (y-axis, lineseries). My data often contains zeros. I've noticed that when this is the case, the y-axis behaves badly. When there is a zero, the minimum value is set to 1.

When all values are smaller than 1 this fails badly (see example)


var rand = new Random();
var rand_seq = Enumerable.Repeat(0, 100).Select(i => rand.NextDouble()).ToArray();
rand_seq[20] = 0;
var chart = new NCartesianChart();
nChartControl1.Charts.Add(chart);
var line = new NLineSeries();
line.DataLabelStyle.Visible = false;
chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator = new NLogarithmicScaleConfigurator();

chart.Series.Add(line);
line.Values.FillFromEnumerable(rand_seq);
nChartControl1.Refresh();


Also, when using larger values than 1, it seems that the value of log(0) is simply set to 1. This tricks the user into believeing that the data point is 1 instead of zero. What I would like, is a solution where points neighboring log(0) simply are plot with a vertical line (i.e. simulating minus infinity).

Is there any way to achieve this?

best regards

Fredrik Östlund


Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Today @ 4:29 AM
Posts: 3,054, Visits: 4,000

Hi Fredrik,

The behavior of zero values in log axes primarily targets charts with zero scale origin (like bar), which look "good" when zeros are present next to valid values. Sure we can add a mapping function that observes a region of say [0, 0+alpha] and maps it to something that will not generate floating point errors (very large or double.Infinity will cause numeric instability in tick, inflate and other calculations). We'll investigate this further and keep you posted... 



Best Regards,
Nevron Support Team



Fredrik Östlund
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 4, Visits: 1
Hi,

I modified a charting library (Chaco) for python before. What needs to be done is:

1) Change the rendering function to plot a vertical line from any point neighboring a zero to the bottom of the plot. That gives the behavior that log zero is mapped to minus infinity.

2) Change the auto scaling the the axis so zeros are ignored.

Just changing zeros to a small value is possible I guess, but less clean. Also, the autoscaling still has to ignore these small values, otherwise the log plot will be dominated by those, leaving the relevant data as a horizontal line at the top.

hope that helps

Fredrik Östlund



Similar Topics


Reading This Topic