Python 重复图表
我正试图设计一个情节:Python 重复图表,python,plot,repeat,altair,Python,Plot,Repeat,Altair,我正试图设计一个情节: import altair as alt from vega_datasets import data movies = data.movies.url base = alt.Chart(movies).mark_bar().encode( alt.Y('count()')).properties( width=200, height=150 ) chart = alt.vconcat() for x_encoding in ['IMDB_Ratin
import altair as alt
from vega_datasets import data
movies = data.movies.url
base = alt.Chart(movies).mark_bar().encode(
alt.Y('count()')).properties(
width=200,
height=150
)
chart = alt.vconcat()
for x_encoding in ['IMDB_Rating:Q', 'IMDB_Votes:Q']:
row = alt.hconcat()
for maxbins_encoding in [10, 50]:
row |= base.encode(alt.X(x_encoding,
type='quantitative',
bin=Bin(maxbins=maxbins_encoding)))
chart &= row
chart
这很有效。然后我尝试使用alt.repeat()
:
它向我提供了以下错误消息:
SchemaValidationError: Invalid specification
altair.vegalite.v3.schema.core.BinParams->maxbins, validating 'type'
{'repeat': 'column'} is not of type 'number'
所以我一定错过了什么。它是否与在
bin=bin()
参数中使用repeat()
有关,而不是直接在encode()
中使用它?不幸的是,重复条目不能用于bin参数。在Vega Lite中使用repeat的唯一参数是传递给编码的列名,因此您最初的循环方法可能是最好的
如果要利用x编码的重复,可以执行以下操作:
def make_column(maxbins):
return alt.Chart(movies).mark_bar().encode(
alt.X(alt.repeat("row"), type='quantitative',
bin=alt.Bin(maxbins=maxbins)),
alt.Y('count()')
).properties(
width=200,
height=150
).repeat(
row=['IMDB_Rating', 'IMDB_Votes'],
)
make_column(10) | make_column(50)
def make_column(maxbins):
return alt.Chart(movies).mark_bar().encode(
alt.X(alt.repeat("row"), type='quantitative',
bin=alt.Bin(maxbins=maxbins)),
alt.Y('count()')
).properties(
width=200,
height=150
).repeat(
row=['IMDB_Rating', 'IMDB_Votes'],
)
make_column(10) | make_column(50)