-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting of alt.Columns should be similar to alt.Colors? #940
Comments
Apparently this issue is closely related to vega-lite vega/vega-lite#3854, AFAICT. |
Altair data is encoded as JSON, which does not have a categorical type, so all pandas categories will be converted to simple strings. If you'd like to specify the explicit order in which a nominal category will appear, you can use the import altair as alt
import pandas as pd
data = pd.DataFrame({'a': list('ABC'),
'b': [28, 55, 43]})
alt.Chart(data).mark_bar().encode(
x='b:Q',
y=alt.Y('a:O', sort=['B', 'A', 'C'])
) |
@jakevdp, the type of sorting I am trying to accomplish is in the https://altair-viz.github.io/gallery/grouped_bar_chart.html Changing |
Ah, my mistake. Sorry. |
@brainstorm Not sure if you still have this issue. I was also trying to figure it out for a while but @jakevdp's approach actually works in the |
This was fixed in the most recent Vega-Lite release, I believe. Update your renderer, and things should work properly. |
Exactly how do I go about doing this? Upgrade ipyvega? Is that just for notebook? Do I need to do the following for JupyterLab? I still go back/forth between vanilla notebooks and JupyterLab since a few things occasionally seem to be more flaky in one than the other, and vice-versa. |
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. |
Hello, I'm having the same issue with ordering the column in a grouped bar chart. It looks like To illustrate, using: "encoding": {
"color": {"type": "nominal", "field": "year"},
"column": {"type": "nominal", "field": "site",
"sort": ["Waseca", "Duluth"]},
"x": {"type": "ordinal", "field": "year"},
"y": {"type": "quantitative", "aggregate": "sum", "field": "yield"}
}, ... where the Note that the first two column are not the ones specified. |
Confirmed that sorting doesn't work in this case. It appears to be a bug in Vega-Lite: I'd suggest filing an issue there. |
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: |
While trying to apply a custom ordering to the
columns
chart spec here: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):
Is ignored by Altair's column ordering :_/ Also, according to the API reference for alt.Column, that only supports
ascending
anddescending
sort=
arguments, unlike i.e alt.Colors which supports a manually orderedList(String)
.I'm currently trying to figure out some workaround while reading through #245, #899, #898 and #397, I just wanted this usecase to be noted ;)
The text was updated successfully, but these errors were encountered: