faceted layered chart errors out while "validating 'anyOf'"
See original GitHub issueI 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
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:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@jakevdp I the transform_lookup is what makes most sense. Thanks!