Gadfly.jl
Gadfly.jl copied to clipboard
Format option for log scale.
Sometimes I'd like my axis to be labelled 1, 10, 100 instead of 10^0, 10^1, 10^2. I thought the format option should do that (Scale.x_log10(format=:plain)
) but apparently that's not the case. Actually setting the format to scientific labels things 10^1x10^0
which is not very useful.
I know that I can use the labels
option to format my labels, but we could probably make better use of the format
option here, no ?
As you note, the difference between format
and labels
is:
-
format
changes the notation of numbers in the label -
labels
is used to change the label format e.g. 10² or 100 or e4.60517
The notation of numbers is changed via the function showoff
e.g. Gadfly.showoff([10.0], :scientific)
, which is then passed to the labelling function.
To change this, some design discussion would be needed, so please outline your ideas about notation and labelling.
I would just do something like this for log10_formatter
:
function log10_formatter(xs::AbstractArray, format=:scientific)
if format == :plain
return [@sprintf("%s", x) for x in showoff((x -> 10^x).(xs), format)]
else
return [@sprintf("10<sup>%s</sup>", x) for x in showoff(xs, :plain)]
end
end
Which seems to work fine except I'm getting to many decimals displayed in the plain format.
Basically make the scientific format the default for log scales (10^x is the scientific format after all).
+10^2 for making it easy to display 100! :)
i like @jonathanBieler 's approach.
lots of decimals are displayed by showoff because it is being called with an extended range of tick marks, not just the ones displayed. put @info xs
into the code in the preceeding comment to demonstrate. one can suppress this behavior by setting extend_tick
to false
here. i believe the reason for the extension is to facilitate panning and zooming in SVGJS. the code which decides what extra tick marks to add seems to presume a linear scale. not sure how best to change it for log scales.