question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting of alt.Columns should be similar to alt.Colors?

See original GitHub issue

While 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:

skarmavbild 2018-06-12 kl 10 49 10

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:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
jakevdpcommented, Nov 28, 2018

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.

1reaction
jan-matthiscommented, Oct 1, 2020

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:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sorting based on the alt.Color field in Altair - Stack Overflow
The chart is currently sorted according to the species column in alphabetical order, but I would like it sorted by the group so...
Read more >
Sort by Color in Excel - WallStreetMojo
1. First, select the entire data table from A1 to B22. 2. Now, go to the "Data" tab (ribbon) and select "Sort." (You...
Read more >
How to Sort By Color in Excel (in less than 10 seconds)
In the 'Order' drop-down, select the first color based on which you want to sort the data. It will show all the colors...
Read more >
altair.Column — Altair 4.2.0 documentation
Sort order for the encoded field. For continuous fields (quantitative or temporal), sort can be either "ascending" or "descending ...
Read more >
How to alternate row color in Excel (highlight every other row)
Once you do this, the odd and even rows in your table will get shaded with different colors automatically. The best thing is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found