LogAxis with very low Values

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
brimborium
Posts: 23
Joined: Mon Dec 13, 2010 10:23 am
antibot: No, of course not.

LogAxis with very low Values

Post by brimborium » Thu Mar 29, 2012 9:40 am

Hi there,

I am currently trying to plot very small values for an allen variance plot. These values can range down to 1E-25. I am using a LogAxis for that, which does not work. Am I doing something wrong or is LogAxis not meant for those kind of values? If not, do you know of any alternatives?

Here is a small example. Make sure to include jcommon-1.0.16.jar and jfreechart-1.0.13.jar. I guess the version does not matter that much.

Code: Select all

import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.LogAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class Demo {
	public static void main(String[] args) {
		XYSeries test = new XYSeries("Testdata");
		double exp = -5, noiseExp = 2; // works as expected
		// double exp = -15, noiseExp = 2; // does not show any values
		for (double tau = 1E-8; tau < 1E-1; tau *= 2)
			test.add(tau, Math.pow(10, exp + (Math.random() - 0.5) * noiseExp), false);
			// test.add(tau, Math.pow(10, exp + (Math.random() - 0.5) * noiseExp) * 1E10, false); // with this, it works also for exp=1E-15
		test.fireSeriesChanged();

		JFreeChart chart = ChartFactory.createXYLineChart("", "", "", new XYSeriesCollection(test), PlotOrientation.VERTICAL, false, false, false);
		chart.getXYPlot().setDomainAxis(new LogAxis("tau"));
		chart.getXYPlot().setRangeAxis(new LogAxis("testdata"));
		JFrame frame = new JFrame("plot");
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.add(new ChartPanel(chart));
		frame.setVisible(true);
		frame.setSize(400, 300);
	}
}
On line 14/15 you can switch between working and not working. You can see, that all the values are shown when they are in the range of 1E-5 (or higher). Somewhere arround 1E-9 they disappear (depends of course on what Math.random() generates). I am a bit lost on what is going on here. Is this a numerical problem? Should not be, because if I just scale up the values before adding them to the series (by multiplication of 1E10, see line 17/18), the values show up fine.

The following pictures show you the output. Left: working (exp=-5); Right: not working (exp=-15)

Image Image

Any help would be appreciated.

Thanks a lot,
Stefan

Locked