Vega: Floating point issues with large enough bin thresholds

Created on 4 Apr 2021  Â·  4Comments  Â·  Source: vega/vega

Bin ticks are occasionally formatted with floating point issues by default. Empirically, it appears to be an issue only when using many bins. Ideally, the vertical bin ticks would be formatted here to something cleaner automatically, like ".1f" in this case.

Open in a Vega Editor.

image

Perhaps related to https://github.com/vega/vega/issues/1395, although the issue still persists.

All 4 comments

This is probably a Vega issue. We cannot automatically add a formatted since Vega-Lite doesn't see the data.

Looks like this is due to use of an ordinal scale, which does not provide automatic formatting. The “standard” way in Vega(-Lite) of plotting binned quantitative fields along an axis is to use a continuous (eg linear) scale and plot both x/x2 or y/y2 for the binned interval. Using a continuous axis will invoke logic to calculate the numeric precision and format the labels accordingly - and also ensures any gaps (empty bins) stay visible. For an ordinal or nominal axis (for which the input could be an arbitrary data type) you currently need to specify the desired axis format (such as “.1f”).

In Vega-Lite the use of continuous scales is invoked automatically when using the bin transform as part of a visual encoding specification. However in this case the binning is being performed earlier via explicit transforms and an ordinal axis is explicitly specified. There may be some Vega-Lite docs or examples about using pre-binned data? (cc @domoritz)

p.s. @domoritz, VL doesn’t need to see the data here in order to know that the inputs are binned quantities. In this case that info is in the spec transformation lineage.

Also, here is an alternative example using quantitative scales for the binned intervals.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

david-littlefield picture david-littlefield  Â·  4Comments

Fil picture Fil  Â·  5Comments

mattijn picture mattijn  Â·  3Comments

pelotom picture pelotom  Â·  3Comments

kanitw picture kanitw  Â·  3Comments