Skip to content
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

How facet resolves multiple records for the facetted parameter not documented #27

Open
mcp292 opened this issue Aug 4, 2022 · 2 comments

Comments

@mcp292
Copy link

mcp292 commented Aug 4, 2022

Please let me know if there is a forum specifically for Altair questions and help and I will move this there.

I haven't been able to find in the documentation how facet resolves multiple entries for the facetted parameter.

In the MWE below, what does facet() do when it encounters 3 entries where P = HD, and T = 0, yet only plots one value at HD, 0 in the t_facet (T) plot.

Is this just a flawed plot?

MWE

import pandas as pd
import altair as alt


data = [{"P": "HD", "T": 0,  "C":100, "Max": 1},
        {"P": "HD", "T": 0,  "C":400, "Max": 3},
        {"P": "HD", "T": 0,  "C":800, "Max": 0},
        {"P": "HD", "T": 23, "C":100, "Max": 2},
        {"P": "HD", "T": 23, "C":400, "Max": 1},
        {"P": "HD", "T": 23, "C":800, "Max": 1},
        {"P": "HD", "T": 80, "C":100, "Max": 7},
        {"P": "HD", "T": 80, "C":400, "Max": 2},
        {"P": "HD", "T": 80, "C":800, "Max": 1},
        {"P": "LD", "T": 0,  "C":100, "Max": 1},
        {"P": "LD", "T": 0,  "C":400, "Max": 2},
        {"P": "LD", "T": 0,  "C":800, "Max": 7},
        {"P": "LD", "T": 23, "C":100, "Max": 7},
        {"P": "LD", "T": 23, "C":400, "Max": 1},
        {"P": "LD", "T": 23, "C":800, "Max": 0},
        {"P": "LD", "T": 80, "C":100, "Max": 2},
        {"P": "LD", "T": 80, "C":400, "Max": 0},
        {"P": "LD", "T": 80, "C":800, "Max": 1}]

df = pd.DataFrame(data)

chart = alt.Chart(df).mark_bar().encode(x="P:N", y="Max:Q", color="P:N")

t_facet = chart.facet("T:N")
c_facet = chart.facet("C:N")
     P   T    C  Max
0   HD   0  100    1
1   HD   0  400    3
2   HD   0  800    0
3   HD  23  100    2
4   HD  23  400    1
5   HD  23  800    1
6   HD  80  100    7
7   HD  80  400    2
8   HD  80  800    1
9   LD   0  100    1
10  LD   0  400    2
11  LD   0  800    7
12  LD  23  100    7
13  LD  23  400    1
14  LD  23  800    0
15  LD  80  100    2
16  LD  80  400    0
17  LD  80  800    1

t_facet
c_facet

@jakevdp
Copy link
Member

jakevdp commented Aug 4, 2022

Because you haven't done any aggregation, in the location of duplicates the chart draws multiple bars plotted on top of each other, and the largest one dominates. You can see this better if you use mark_point() in place of mark_bar().

@mcp292
Copy link
Author

mcp292 commented Aug 4, 2022

Ah! Thank you! Where should I ask questions in the future?

My next question is how would you recommend displaying data of this dimension then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants