Sorting of alt.Columns should be similar to alt.Colors?
See original GitHub issueWhile trying to apply a custom ordering to the columns
chart spec here:
logplot = alt.Chart(dataset_curated).mark_bar().encode(
alt.X('technology:N', scale=alt.Scale(rangeStep=15), axis=alt.Axis(title='')),
y = 'log:Q',
color = alt.Color('sample:N'),
column = 'chromosome:N'
#column = alt.Column('chromosome:N', sort=alt.SortField(order=chr_array))
)
The column strings seem to be ordered lexicographically, not ideal for i.e, chromosomes:
So my pandas Categorical ordering, which works for raw dataframe ordering (chromosomes ordered by array’s positions):
chr_array = ['chr'+str(x) for x in range(1,23)]
chr_array.append('chrX')
chr_array.append('chrY')
chr_array.append('chrM')
dataset_curated["chromosome"] = pd.Categorical(dataset_curated["chromosome"], chr_array)
dataset_curated = dataset_curated.sort_values("chromosome")
Is ignored by Altair’s column ordering :_/ Also, according to the API reference for alt.Column, that only supports ascending
and descending
sort=
arguments, unlike i.e alt.Colors which supports a manually ordered List(String)
.
I’m currently trying to figure out some workaround while reading through https://github.com/altair-viz/altair/issues/245, https://github.com/altair-viz/altair/pull/899, https://github.com/altair-viz/altair/issues/898 and https://github.com/altair-viz/altair/issues/397, I just wanted this usecase to be noted 😉
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
For jupyter notebook, you need to update ipyvega.
For jupyterlab, vega-lite is bundled with jupyterlab itself. If you update to the most recent version of jupyterlab you’ll get the most recent version of the vega-lite renderer.
If you go back and forth between both, you’ll need to update both.
I ran into the same issue as @andreipoe. To save the next person from searching – there are two issues in Vega-Lite that seem related: