Reputation: 4605
Suppose we have:
import altair as alt
from vega_datasets import data
import sys
source = data.wheat()
chart = (
alt.Chart(source)
.mark_trail()
.encode(x="year:O", y="wheat:Q", size="wheat:Q")
)
sys.displayhook(chart)
I'd like to swap out the source
data for the chart for some other dataset, but leave everything else the same. How can I do so?
Upvotes: 0
Views: 12
Reputation: 4605
Re-assign the data
field on the chart:
import altair as alt
from vega_datasets import data
import sys
source = data.wheat()
chart = (
alt.Chart(source)
.mark_trail()
.encode(x="year:O", y="wheat:Q", size="wheat:Q")
)
sys.displayhook(chart)
another_source = source[source.year > 1750]
chart.data = another_source
sys.displayhook(chart)
Upvotes: 0