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.

faceted layered chart errors out while "validating 'anyOf'"

See original GitHub issue

I was trying to reproduce a custom non-altair/vega chart I saw online when I ran into some trouble.

When faceting a chart then layering it - produces this error:

---------------------------------------------------------------------------
SchemaValidationError                     Traceback (most recent call last)
C:\Users\jthomp261\AppData\Local\Continuum\anaconda3\envs\data_analysis\lib\site-packages\altair\vegalite\v2\api.py in to_dict(self, *args, **kwargs)
    338         if dct is None:
    339             kwargs['validate'] = 'deep'
--> 340             dct = super(TopLevelMixin, copy).to_dict(*args, **kwargs)
    341 
    342         if is_top_level:

C:\Users\jthomp261\AppData\Local\Continuum\anaconda3\envs\data_analysis\lib\site-packages\altair\utils\schemapi.py in to_dict(self, validate, ignore, context)
    252                 self.validate(result)
    253             except jsonschema.ValidationError as err:
--> 254                 raise SchemaValidationError(self, err)
    255         return result
    256 

SchemaValidationError: Invalid specification

        altair.vegalite.v2.api.LayerChart->layer->items, validating 'anyOf'

Here is the non-faceted that works:

import altair as alt
from vega_datasets import data

stocks = data.stocks()
# get the price on the most recent date for the point chart
stocks_max = pd.merge(stocks.groupby('symbol')['date'].max().reset_index(),
                      stocks, on=['symbol', 'date'], how='left')

point = alt.Chart(stocks_max).mark_point().encode(
    x='date:T',
    y='price',
    color='symbol')

line = alt.Chart(stocks).mark_line(color='red').encode(
    x='date:T',
    y='price',
    color='symbol')

line+point

visualization

Now when I change the

color='symbol'

to

row='symbol'

so that the bottom part looks like this:

point = alt.Chart(stocks_max).mark_point().encode(
    x='date:T',
    y='price',
    row='symbol')

line = alt.Chart(stocks).mark_line(color='red').encode(
    x='date:T',
    y='price',
    row='symbol')

line+point

I then get the error mentioned above.

I have searched on this repo and on vega-lite’s repo for layered facets with many results of errors but they were all different from this one. I may be missing something basic here.

Note: this is not the completed chart, was was going to layer on another bar plot to get some other effect, but hit this roadblock on the way.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
anitagrasercommented, Jan 4, 2019

It would be great to add this limitation as a side note to the example at https://altair-viz.github.io/gallery/choropleth_repeat.html. As soon as the user tries to add another map layer, the chart is broken and the error message is rather cryptic. Took me a while to find this issue report.

1reaction
gh-owestessoncommented, Jul 30, 2018

@jakevdp I the transform_lookup is what makes most sense. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bar Chart in Altair: ValueError: Faceted charts cannot be layered
Does anyone have suggestions to avoid the error? ValueError: Faceted charts cannot be layered. With this Pandas Dataframe
Read more >
altair.LayerChart — Altair 4.1.0 documentation
A Chart with layers within a single panel Mapping(required=[layer]). Attributes ... Instead, use the facet operator and place a layer inside a facet....
Read more >
Changelog | ArcGIS Hub
Now when a Tiled Imagery Layer appears in the search results, it will show a map icon, along with an "Image Service" type...
Read more >
Verification and Validation in Computational Fluid Dynamics1
Verification and validation (V&V) are the primary means to assess accuracy and reliability in computational simulations. This paper presents an extensive ...
Read more >
Risk Management Guide for Information Technology Systems
When a vulnerability can be exercised ➞apply layered protections, architectural designs, and administrative controls to minimize the risk of or prevent this.
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