jfree / jfreechart

A 2D chart library for Java applications (JavaFX, Swing or server-side).
http://www.jfree.org/jfreechart/
GNU Lesser General Public License v2.1
1.22k stars 463 forks source link

LogarithmicAxis #301

Closed datahaki closed 2 years ago

datahaki commented 2 years ago

I wanted to reproduce the example from Mathematica

https://reference.wolfram.com/language/ref/ListLogPlot.html#1122321828

when using JFreeChart default settings (without manual tweaks) the y-axis number/tick labels get crammed

ListLogPlotDemo

the ticks seems to be forced as 1, 10, 100, 1000, 1E4, etc. instead of perhaps 1, 1000, 1E6, etc.

trashgod commented 2 years ago

To get a narrower display, try setExpTickLabelsFlag(true) on the LogarithmicAxis. To mitigate vertical crowding, you may need to increase the height or look at a custom implementation of refreshTicksVertical(), as suggested here.

datahaki commented 2 years ago

thanks for the info!

I just expected the same default behavior as when using the standard (linear?) axis, which automatically adjusts tick spacing.

The plot below uses same data than from above but linear axis in jFreeChart:

ListLogPlotDemo

trashgod commented 2 years ago

Yes. Note how the newer LogAxis, suggested here, extends ValueAxis and overrides refreshTicks to achieve this, while the older LogarithmicAxis extends NumberAxis with a different approach to tick units.

datahaki commented 2 years ago

thank you very much - LogAxis did the trick!

ListLogPlotDemo