Non-deterministic behavior with `mark_boxplot`
See original GitHub issueThe following code will not order the categories on the x-axis the same way on repeated runs:
import pandas as pd
import numpy as np
import altair as alt
d = pd.DataFrame({
'x': np.repeat(np.arange(3), 10),
'y': np.concatenate([np.random.normal(i, 0.1, 10) for i in range(3)]),
'z': np.repeat(np.arange(3, 0, -1), 10),
}).sort_values(
'z',
)
alt.Chart(
d,
).mark_boxplot(
opacity=1.0,
).encode(
x=alt.X('x:N', sort=None),
y='y:Q',
color='z:N',
)
This does not seem to happen with mark_circle
.
My understanding was that using sort=None
with alt.X
would respect the order in the data (i.e., z
).
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (11 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just switched to my mac and tried on safari, and I can see the behavior you reported (it works fine on Chrome and Firefox). It’s not an Altair issue, but rather a Vega-Lite issue (You can see it here in the vega editor).
I spent a while trying to find Safari’s developer tools to attempt to diagnose the issue, but gave up because it’s Saturday night 😄
I would report this issue on the Vega-Lite issue tracker.
As to other question about identifying a plotting library that shows plotted boxes placed mathematically instead of categorically in a box-plot, if you would like to force bins without data to be part of the x scale, in Altair you can use the scale
domain
argument: