简体   繁体   English

Altair '4.1.0' 返回一个空图表

[英]Altair '4.1.0' returning an empty chart

I'm trying to add a symbol in my Altair chart so the user could know by color what each line represents in the chart, but when I plot it I receive an empty chart without the data I'm passing.我正在尝试在我的 Altair 图表中添加一个符号,以便用户可以通过颜色知道图表中每条线所代表的内容,但是当我使用 plot 时,我收到一个没有我传递的数据的空图表。

Meanwhile I was debugging the code and I suppose the problem is located on the line color = alt.Color...同时我正在调试代码,我想问题出在color = alt.Color...

base = alt.Chart(new_df, title="Mean Control Chart").properties(width=600,height=500)

domain = ['Mean','LSC','LM','LIC','1 x S(+)','2 x S(+)','1 x S(-)','2 x S(-)']
range_ = ['black','red','green','red','blue','blue','blue','blue']

# Linha da media
media_chart = base.mark_line(point=True).encode(
    alt.X('amostra',type='quantitative', title='Samples', scale=alt.Scale(domain=(x_range_min_1,x_range_max_1))),
    alt.Y('media', type='quantitative', title='Mean', scale=alt.Scale(domain=(y_range_min_1,y_range_max_1))),
    color = alt.Color('Symbol',type='nominal', scale=alt.Scale(domain=domain, range=range_))
)

我正在使用的数据集的图像

我得到的空图表

Dataset数据集

You cannot use "Symbol" as the chart color because it is not a column in your dataframe.您不能使用“符号”作为图表颜色,因为它不是 dataframe 中的列。 You would need to reshape/melt the df first to create this column, eg with new_df.melt(id_vars=['amostra', 'media'], var_name='Symbol'] as per the pandas docs on reshaping .您需要先重塑/融化 df 以创建此列,例如使用new_df.melt(id_vars=['amostra', 'media'], var_name='Symbol']根据pandas docs on reshaping

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM