【问题标题】:More colors in my Python Altair Chart. Wider spectrum of colors我的 Python Altair 图表中有更多颜色。更广泛的色彩范围
【发布时间】:2021-07-04 19:24:14
【问题描述】:

早上好。我有以下图像:

以下代码:

data = pd.read_csv(os.path.join(path_to_folder,"file.csv"))

chart = alt.Chart(data.reset_index(),title="Visualisation").mark_point().encode(
    x ="x",
    y ="y",
    color = 'id_species'
).encode(tooltip=['x','y','id_species'])

chart.encoding.x.title = 'first parameter'
chart.encoding.y.title = 'second parameter'

chart.show()

如果我想让颜色从紫色变为绿色,我该怎么做?如果我想要更广泛的颜色而不是蓝色阴影?*

(我是用 matplotlib 做的,但我想用 Altair 做。)

【问题讨论】:

    标签: python charts colors altair


    【解决方案1】:

    This page from the altair documentation 描述了如何更改配色方案。例如:

    import altair as alt
    from vega_datasets import data
    
    iris = data.iris()
    
    alt.Chart(iris).mark_point().encode(
        x='petalWidth',
        y='petalLength',
        color=alt.Color('species', scale=alt.Scale(scheme='dark2'))
    )
    

    你想要的配色方案在 altair 中称为 'viridis',就像在 matplotlib 中一样。

    【讨论】:

    • 非常感谢,这正是正确的答案。祝你有美好的一天!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2020-11-24
    • 2020-05-10
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多