Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 重复图表_Python_Plot_Repeat_Altair - Fatal编程技术网

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)