ChartDirector General Forum Home   Search
Log axis scale question
Posted by at on Jul-07-2023 17:16
Hi Peter, if I'm setting a y-axis to log scale with min limit of -1000 and max limit of 1000, Chartdirector only displays 0.1, 1, 10, 100, 1000, but if i set it from -1000 to 0, it would display -1000, -100, -10, -1, -0.1. Why is it that a log scale can't display negative to positive axis?

Re: Log axis scale question
Posted by Peter Kwan on Jul-08-2023 14:12
Hi at,

Would you mind to clarify what do you expect to see if the log scale is from 1000 to -1000?

The log scale is like 1000, 100, 10, 1, 0.1, 0.01, 0.001, 0.0001, 0.00001,  .... No matter how long you extend the scale, it can never reach zero. In maths, log(x) tends to negative infinitely when x tends to 0, and log(0) is undefined. That's why you cannot extend a positive log scale to 0 or negative, and vice versa. If the scale can include 0, then it is not a log scale.

Best Regards
Peter Kwan

Re: Log axis scale question
Posted by at on Jul-10-2023 09:26
Attachments:
Hi Peter, I'm expecting it to display something like -1000, -100, -10, -1, 1, 10, 100, 1000 since Chartdirector is capable of displaying negatives, see attached.

Re: Log axis scale question
Posted by Peter Kwan on Jul-10-2023 17:47
Hi at,

To be a log scale, the ratios between evenly spaced labels should be a fixed value, such as 10 in your case. For your labels, the ratio between -1 and 1 is not 10, so it is not a log scale.

A log scale should be like:

-1000, 100, -10, -1, -0.1, -0.01, -0.001, -0.0001, -0.00001, -0.000001, ......

and it can never reach the positive side. The distance between -1 and 1 is infinite or undefined. That why a log scale cannot have both positive and negative values.

For your case, if the positive and negative points do not connect together (that is, there is no line joining a positive point with a negative point), you can consider your chart to consist of two data sets for the positive and negative points, and they use two different log axes - one is from -1000 to -1, and the other from 1 to 1000. The distance between -1 to 1 is undefined, and for your case you can set to any distance you want.

The following is a method to use two different axis but make it looks like a single axis.

(a) In ChartDirector, by default, the height of the y-axis will be equal to the height of the plot area. It is possible to add "margins" to the y-axis so that the axis only occupies part of the plot area border. The following is an example that the y-axis is shortened at the top-end to leave space for the legend box.

The key API is Axis.setMargin:

(b) It is possible to add two y-axis on the same side of the plot area. The following is an example: