Hi,
I am working on a line chart that has logarithmic axis for both x and y. The data range is over several decades and I would like exponential numbers on the axis.
Example: 0.00000001 doesn't look good. I would like to see 1.0e-9 or 10-9 or something like that.
Does anyone know how to do this? If log axis are available, exp. notation for numbers should also be available.
Thanks
Alfi
Logarithmic Axis - How can I use exponential numbers
-
- Posts: 3
- Joined: Mon Jul 24, 2006 11:01 pm
-
- Posts: 18
- Joined: Thu May 11, 2006 11:22 pm
You want something like:
This is also handy when using a DateAxis - the default date format for a DateAxis gets messed up if, in a chart with a multi-day range, you zoom down to a narrow timerange and then back. It starts off including the date and time, drops the date when you zoom in, and doesn't add it back when you zoom back out. If you set your own DateFormat, that doesn't happen.
Code: Select all
LogarithmicAxis myLogAxis = new LogarithmicAxis("Test");
NumberFormat numFormat = new DecimalFormat("0.###E0");
myLogAxis.setNumberFormatOverride(numFormat);
-
- Posts: 3
- Joined: Mon Jul 24, 2006 11:01 pm
Thanks. That works but only with numbers greater/equal 1. Numbers smaller 1 are not changed. This looks funny. My code is slightly different, but this should make no difference ?
Any idea what this could be? In my opinion this should work for all numbers or not at all.
Code: Select all
NumberAxis domainAxis = new LogarithmicAxis("xxx");
NumberAxis rangeAxis = new LogarithmicAxis("YYYY");
...
NumberFormat numFormat = new DecimalFormat("0.###E0");
rangeAxis.setNumberFormatOverride(numFormat);
-
- Posts: 18
- Joined: Thu May 11, 2006 11:22 pm
I'm not sure; my log data doesn't have any fractional values, so I hadn't run into that before. I'm not actually even sure how to get gridlines for sub-1 values to show up, as changing the tick unit doesn't seem to do it.
However, while looking for that, I did discover something else that might work for you: logAxis.setLog10TickLabelsFlag(true)
It sets the tick labels to 10^X format, without messing with an explicit NumberFormat.
However, while looking for that, I did discover something else that might work for you: logAxis.setLog10TickLabelsFlag(true)
It sets the tick labels to 10^X format, without messing with an explicit NumberFormat.
-
- Posts: 3
- Joined: Mon Jul 24, 2006 11:01 pm
The setLog10TickLabelsFlag(true) works over the complete range. Thanks.
I ran a small test with the DecimalFormat:
This works perfectly, but it does not with the line chart.
I ran a small test with the DecimalFormat:
Code: Select all
double[] test = {123.23,12.9,1.543,0.986,0.002345,0.0000005678,-0.2348,-23.9};
DecimalFormat dec = new DecimalFormat ("0.###E0");
for (int n=0; n<test.length; n++) {
System.out.println(dec.format(test[n])); }
Output:
1.232E2
1.29E1
1.543E0
9.86E-1
2.345E-3
5.678E-7
-2.348E-1
-2.39E1
Re: Logarithmic Axis - How can I use exponential numbers
I also have plots will low values, and with logarithmic axis or not, under 1e-7 I only have ONE value in the axis scale which is a problem.Alfi@leman wrote:Example: 0.00000001 doesn't look good. I would like to see 1.0e-9 or 10-9 or something like that.
Alfi
SAMTECH, Integrating CAE towards Professional Solutions : www.samcef.com