altair
altair copied to clipboard
Sorted Row + Column with `sort` argument - Faceted Chart does not show data correctly
Hi peeps,
I am running the code with the following environment:
- Python version: 3.7.4 (default, Oct 24 2019, 16:20:49) [Clang 11.0.0 (clang-1100.0.33.8)]
- Altair version: 4.1.0
It seems to me that the faceted chart does not show correctly if I facet it by Row and Column and throwing sort
argument.
I have looked into other question and tried the sort
argument with altair.Row
and altair.Column
.
I'd really appreciate if you could point out something I am missing here. The following code would reproduce the issue:
Thanks!
import pandas as pd
import altair as alt
import sys
from io import StringIO
print(f"Python Version: {sys.version}")
print(f"Altair version: {alt.__version__}")
selection = alt.selection_single(on='mouseover')
w = 100
h = 100
x_domain = (-100, 100)
y_domain = (-200, 200)
data = """ x y Project Stage
0 -10.540327 61.649657999999995 P1 S2
1 32.379704 -130.71579599999998 P1 S2
2 -2.620516 71.260701 P1 S2
3 13.978546 31.711221000000002 P1 S4
4 41.391873 88.070636 P1 S4
5 -0.303671 -84.376145 P1 S4
6 -65.370553 -7.694756 P2 S3
7 9.062894 177.233938 P2 S3
8 17.029269 -100.364923 P2 S3
9 13.354712 73.78603100000001 P2 S2
10 18.781817999999998 -109.3554 P2 S2
11 67.189193 113.94348000000001 P2 S2
12 8.762746 128.735548 P2 S1
13 59.287251 11.017662 P2 S1
14 -2.4981430000000002 -166.897776 P2 S1
15 1.1900870000000001 -82.309501 P3 S3
16 21.938575 -118.20861699999999 P3 S3
17 45.414544 122.49246000000001 P3 S3
18 -36.322626 -63.310702 P3 S2
19 53.568994999999994 141.37641100000002 P3 S2
20 26.129929999999998 153.706601 P3 S2
21 -3.9384330000000003 102.90164399999999 P3 S6
22 -8.198288 137.616797 P3 S6
23 -8.240618 -146.80676 P3 S6
24 15.193395 25.697023 P3 S5
25 20.886185 68.356337 P3 S5
26 -22.101129999999998 89.639481 P3 S5"""
exp = pd.read_csv(StringIO(data), sep='\t')
base = alt.Chart(exp)
point = base.mark_point().encode(
alt.X('x:Q', scale=alt.Scale(domain=x_domain)),
alt.Y('y:Q', scale=alt.Scale(domain=y_domain)),
tooltip=['x', 'y'],
color='Stage:N'
).properties(
width=w, height=h
).facet(
row=alt.Row('Project:N'),
column=alt.Column('Stage:N')
).properties(
title='Correct Data in Faceted Chart'
).configure_title(
orient='top', anchor='middle', color='blue', fontSize=16
)
point.display()
point2 = base.mark_point().encode(
alt.X('x:Q', scale=alt.Scale(domain=x_domain)),
alt.Y('y:Q', scale=alt.Scale(domain=y_domain)),
tooltip=['x', 'y'],
color='Stage:N'
).properties(
width=w, height=h
).facet(
row=alt.Row('Project:N', sort=['P1', 'P2', 'P3']),
column=alt.Column('Stage:N', sort=['S1', 'S2', 'S3', 'S4', 'S5', 'S6'])
).properties(
title='Wrong Data in Faceted Chart'
).configure_title(
orient='top', anchor='middle', color='red', fontSize=16
)
point2.display()
Data Description
Expected Plot
Data is misaligned after throwing sort
argument
It looks like a Vega-Lite bug. I'd suggest finding a simpler vega-lite repro of the issue, and filing a bug there.
same problem here. Any news on this from vega-lite?
Closing this as there is nothing to do from the Altair side of things here. Please open an issue in the VL repo for this and feel free to link it here. Once the functionality has been implemented in VL, it will be in an upcoming Altair release.