marimo altair_chart not displaying log scaled altair chart correctly
Describe the bug
In the example below, the altair chart with passed to mo.ui.altair_chart does not appear to display correctly when the axis is log scaled (not sure if this applies to any other scales)?
(note that I had killed my marimo process when took the screenshot, which is why background is red)
Environment
{ "marimo": "0.6.17", "OS": "Darwin", "OS Version": "23.5.0", "Processor": "arm", "Python Version": "3.10.4", "Binaries": { "Browser": "--", "Node": "v21.7.1" }, "Requirements": { "click": "8.1.7", "importlib-resources": "missing", "jedi": "0.19.1", "markdown": "3.5.2", "pymdown-extensions": "10.7", "pygments": "2.17.2", "tomlkit": "0.12.3", "uvicorn": "0.29.0", "starlette": "0.37.2", "websockets": "12.0", "typing-extensions": "4.9.0", "black": "23.12.1" } }
Code to reproduce
import marimo as mo
import polars as pl
import altair as alt
import pandas as pd
def test(scale_type):
data = {
'x': range(1, 11),
'y': [5, 10, 2, 8, 3, 15, 1, 4, 9, 6]
}
df = pl.DataFrame(data)
# return chart with specified scale type for Y
return (
alt.Chart(df.to_pandas())
.mark_bar(stroke="black", strokeWidth=0.5)
.encode(
x=alt.X(
"x",
),
y=alt.Y(
"y",
scale=alt.Scale(type=scale_type),
),
)
)
# Display the chart
return chart
linear = test("linear")
log = test("log")
sqrt = test("sqrt")
# Display the altair and mo.ui.altair_chart versions alongside one another
mo.hstack([mo.vstack([linear, log, sqrt]), mo.vstack([mo.ui.altair_chart(linear), mo.ui.altair_chart(log), mo.ui.altair_chart(sqrt)])])
Thanks for the easy-to-follow repro. Another interesting bit, when I export both log scales (altair and mo.ui.altair_chart) to the vega editor, neither work:
Still unsure why this fails (even in the vega editor), but symlog seems more reliable than log as a scale setting.
Filed two issues to: https://github.com/vega/altair/issues/3447 https://github.com/vega/vega-lite/issues/9373
Thank you for filing!