Why is Altair returning an empty chart when using log scale?

Try to use symlog (instead log).


The logarithm of zero is negative infinity, which is problematic for display. The renderer produces warnings about this, which you can see in the javascript error log when your chart is rendered:

> WARN A log scale is used to encode bar's x. This can be misleading as the width of the bar can be arbitrary based on the scale domain. You may want to use point mark instead.
> WARN Log scale domain includes zero: [0,770000]

One way around this would be to filter non-positive values out of the chart; e.g.

alt.Chart(df).transform_filter(
    alt.datum.foos > 0  
).mark_bar().encode(
    alt.X('foos', scale=alt.Scale(type='log')),
    y='group'
)

enter image description here

But even then, logarithmic scales are misleading when used with bar charts, because bar charts imply a linear proportionality between the bars and the baseline is arbitrary. I'd suggest either using a linear scale, or a different type of mark to make your chart more clear.

Tags:

Python

Altair