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

.facet does not accept facet=alt.Facet('x', columns=2) as an input #2563

Closed
samesand opened this issue Mar 18, 2022 · 6 comments
Closed

.facet does not accept facet=alt.Facet('x', columns=2) as an input #2563

samesand opened this issue Mar 18, 2022 · 6 comments

Comments

@samesand
Copy link

.facet accepts alt.Facet('x') as a input, but if you add columns as a parameter to alt.Facet it returns a 'data' is a required property error. I think this happens because .facet accepts columns as an argument as well.

Example:
alt.Chart(df).mark_circle().encode(x='x', y='y').facet(facet=alt.Facet('z', columns=2)

If this is not a bug, maybe the documentation for alt.Facet should indicate the expected use of the columns argument (or other arguments that may not work when used in the same manner)

@samesand samesand added the bug label Mar 18, 2022
@joelostblom
Copy link
Contributor

@joelostblom
Copy link
Contributor

This is now a bit more confusing because the new improved error message suggests that columns should work with Facet:

import altair as alt
from vega_datasets import data

source = data.barley.url

alt.Chart(source).mark_point().encode(
    alt.X('median(yield):Q').scale(zero=False),
    y='variety:O',
    color='year:N'
).properties(
    width=200,
    height=100,
).facet(
    alt.Facet('site:O', columns=2),
)

Error message contradicting itself since columns is listed in the existing parameter names:

SchemaValidationError: `Facet` has no parameter named 'columns'

Existing parameter names are:
shorthand      bin       field     timeUnit   
aggregate      bounds    header    title      
align          center    sort      type       
bandPosition   columns   spacing              

See the help for `Facet` to read the full description of these parameters

@dangotbanned
Copy link
Member

This isn't a bug, the issue was how many (f|F)acet variations were used

import polars as pl
import altair as alt

df = pl.DataFrame({"x": [1, 2, 3], "y": [1, 2, 3], "z": [1, 2, 3]})
chart = alt.Chart(df).mark_circle().encode(x="x", y="y")

Error

chart.facet(facet=alt.Facet('z', columns=2))
Traceback

SchemaValidationError: `Facet` has no parameter named 'columns'

Existing parameter names are:
shorthand      bin       field     timeUnit   
aggregate      bounds    header    title      
align          center    sort      type       
bandPosition   columns   spacing              

See the help for `Facet` to read the full description of these parameters

Solution

chart.facet("z", columns=2)
Screenshot

Image

@joelostblom
Copy link
Contributor

The issue is that when you do something like chart.facet(alt.Facet('z', columns=2)), the error message says

SchemaValidationError: `Facet` has no parameter named 'columns'

But then proceeds to list columns as a valid parameter name for alt.Facet:

Existing parameter names are:
shorthand      bin         field     timeUnit   
aggregate      bounds      header    title      
align          center      sort      type       
bandPosition   **columns** spacing              

See the help for `Facet` to read the full description of these parameters

It's not a huge deal, but somewhat confusing and does not point users in the right direction (columns outside alt.Facet as in your solution).

@dangotbanned
Copy link
Member

It's not a huge deal, but somewhat confusing and does not point users in the right direction (columns outside alt.Facet as in your solution).

@joelostblom I do see the error message as being an issue, maybe something to look into as part of #3752?

Its tricky because Facet in this example could refer to either:

import altair as alt
alt.Chart().facet(alt.Facet('z', columns=2))
#           ^^^^^

Or:

import altair as alt
alt.Chart().facet(alt.Facet('z', columns=2))
#                     ^^^^^

@joelostblom
Copy link
Contributor

Maybe something to look into as part of #3752?

That sounds like a good idea!

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

3 participants