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.

When summing two charts with identically ordered axis, the order is lost.

See original GitHub issue

Hi, I’m rather new to the library and this is probably derived from my lack of full understanding of it, but since this behavior is a little bit surprising I wanted to ask if it is expected.

I have two dataframes:

import altair as alt
import pandas as pd

laureates = pd.DataFrame({
    'name': ['B', 'D', 'C', 'A'],
    'born': pd.to_datetime(['1900-01-01', '1905-01-01', '1930-01-01', '1960-01-01']),
    'died': pd.to_datetime(['1950-01-01', '1965-01-01', '1970-01-01', '2015-01-01'])
})

prizes = pd.DataFrame({
    'name': ['B', 'B', 'D', 'C', 'A'],
    'date': pd.to_datetime(['1930-01-01', '1935-05-01', '1936-01-01', '1965-01-01', '2000-01-01'])
})

laureates

prizes

And I did the following two charts:

dots = alt.Chart(prizes.merge(laureates, on='name'))\
    .mark_point(fill='black')\
    .encode(y='date:T', x=alt.X("name:N", sort=["born:T"]))

lines = alt.Chart(laureates)\
    .mark_rule()\
    .encode(y="born:T", y2="died:T", x=alt.X("name:N", sort=["born:T"]))

Independently, both graphs render more or less as I intended: lines

dots

But when I sum them with lines + dots the ordering in the x-axis reverts to alphabetical: lines + dots

Is this expected? If so, how do I keep the original ordering? Or how do I reorder the axis after joining the charts?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Jul 18, 2018

This is a bug in Vega-Lite; see #820 and vega/vega-lite#3710. Closing as a duplicate.

1reaction
jeffbaumescommented, Jul 18, 2018

As @jakevdp suggests in #820, you can update one of your alt.X specifications to turn off the second axis:

alt.X("name:N", sort=["born:T"], axis=alt.Axis(labels=False, ticks=False))
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the plotting order of categories, values, or data series
On a chart, do one of the following: To change the plotting order of categories, click the horizontal (category) axis. · On the...
Read more >
Multiple Time Series in an Excel Chart - Peltier Tech
This discussion mostly concerns Excel Line Charts with Date Axis formatting. Date Axis formatting is available for the X axis (the independent ...
Read more >
An Introduction to Combinatorics and Graph Theory
A permutation of some objects is a particular linear ordering of the objects; P(n, k) in effect counts two things simultaneously: the number...
Read more >
Create a Pareto Chart - Tableau Help
A Pareto chart is a type of chart that contains both bars and a line graph, where individual values are represented in descending...
Read more >
ggplot with 2 y axes on each side and different scales
The original ggplot objet is then manipulated with Kohske's helper function PlotWithFudgeAxis to add a second axis preserving the scales of y2. It...
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