showing float/double axis labels

17 views
Skip to first unread message

Malcolm Wallace

unread,
Dec 3, 2010, 11:01:40 AM12/3/10
to Haskell Chart List
I just came across a small anomaly, where a Chart axis was labelled
with the following sequence of values:

-0.15
-0.1
-5.0e-2
0
5.0e-2
0.1
0.15
0.2

Does anyone else think that the labels for +/-0.05 look out-of-place?
The reason we get 5.0e-2 instead of 0.05 is because we use plain
"show" on labels, and this is the standard haskell behaviour for
showing Float/Double.

The attached patch changes the label-showing function from "show" to
"Numeric.showFFloat", which never uses scientific notation. Whilst it
makes the anomalous example look better, I am not convinced it is
necessarily the best solution for all situations. Any thoughts?

Regards,
Malcolm

floataxis.dpatch

Malcolm Wallace

unread,
Dec 6, 2010, 6:10:17 AM12/6/10
to Haskell Chart List, Malcolm Wallace
> The attached patch changes the label-showing function from "show" to
> "Numeric.showFFloat", which never uses scientific notation.

Actually, that was an incorrect version of the patch. I attach a
corrected version.

Regards,
Malcolm

floataxis.dpatch

Tim Docker

unread,
Dec 7, 2010, 6:53:51 PM12/7/10
to haskell...@googlegroups.com
I've pushed this, thanks.

I agree that a more complex algorithm may be better in the general case,
but this is still
better than the plain old Show that we have now.

Tim

Malcolm Wallace

unread,
Jan 7, 2011, 8:49:06 AM1/7/11
to haskell...@googlegroups.com
I attach an additional patch, which allows the user to supply their
own axis-labelling function to override the default. I use this with
e.g.

dollar, percent :: Double -> String
dollar v = "$"++ show v
percent v = show (v*100) ++ "%"

I am not completely satisfied with this, because although labelling
for most types can be overridden, labelling for dates/times is not,
even if you pass in a custom labeller. But this does an adequate job
for the simpler types.

Regards,
Malcolm

axisLabelling.dpatch

Tim Docker

unread,
Feb 20, 2011, 9:25:48 PM2/20/11
to haskell...@googlegroups.com

> I attach an additional patch, which allows the user to supply their
> own axis-labelling function to override the default. I use this with
> e.g.
>
> dollar, percent :: Double -> String
> dollar v = "$"++ show v
> percent v = show (v*100) ++ "%"
>
> I am not completely satisfied with this, because although labelling
> for most types can be overridden, labelling for dates/times is not,
> even if you pass in a custom labeller. But this does an adequate job
> for the simpler types.
>
> Regards,
> Malcolm

Can you given an example of how this would be used? Is it meant to
simplify the existing way of doing this, which would be something like:

layout = layout1_title ^= "Price History"
...
$ layout1_left_axis ^: laxis_generate ^= autoScaledAxis lap
$ defaultLayout1

lap =defaultLinearAxis{la_labelf_=dollar}

Tim

Reply all
Reply to author
Forward
0 new messages