Altair 散点图
Altair Scatter Chart
我正在寻找一种方法来制作基于多个标称条件的点图。我在 x 和 y 上绘制了 2 个值,但我想根据年份以及 'type'.
来区分这些点
目前,我的做法是将年份分配给颜色,而 'type' 分配给形状
color=alt.condition(selection, alt.Color('Date:T'), alt.value('lightgray'), scheme='red' )
shape = alt.Shape('type:N')
几个问题:
- 是否可以更改点的配色方案而不是默认颜色来表示 red/blue/black 的阴影等?
- 是否可以将一种颜色 scheme/shade(而不是形状)分配给 'types'?
- is it possible to change the color scheme of the points instead of the default colors to say shades of red/blue/black, etc?
是的,请参阅 https://altair-viz.github.io/user_guide/customization.html#customizing-colors. You can use any of the built-in Vega color schemes,或使用此处讨论的方法定义您自己的方法。根据您的示例,它可能看起来像这样:
color=alt.condition(
selection,
alt.Color('Date:T', scale=alt.Scale(scheme='reds')),
alt.value('lightgray')
)
- is it possible to assign one color scheme/shade (instead of shapes) to 'types'?
不,没有内置方法可以根据数据中的两个字段应用两个色标(标记如何在分配给它的两种颜色之间进行选择?)一种可能的方法是使用不透明度第二场的编码,这反映在标记的亮度上。对于您的示例,它可能如下所示:
opacity='type:N'
我正在寻找一种方法来制作基于多个标称条件的点图。我在 x 和 y 上绘制了 2 个值,但我想根据年份以及 'type'.
来区分这些点目前,我的做法是将年份分配给颜色,而 'type' 分配给形状
color=alt.condition(selection, alt.Color('Date:T'), alt.value('lightgray'), scheme='red' )
shape = alt.Shape('type:N')
几个问题:
- 是否可以更改点的配色方案而不是默认颜色来表示 red/blue/black 的阴影等?
- 是否可以将一种颜色 scheme/shade(而不是形状)分配给 'types'?
- is it possible to change the color scheme of the points instead of the default colors to say shades of red/blue/black, etc?
是的,请参阅 https://altair-viz.github.io/user_guide/customization.html#customizing-colors. You can use any of the built-in Vega color schemes,或使用此处讨论的方法定义您自己的方法。根据您的示例,它可能看起来像这样:
color=alt.condition(
selection,
alt.Color('Date:T', scale=alt.Scale(scheme='reds')),
alt.value('lightgray')
)
- is it possible to assign one color scheme/shade (instead of shapes) to 'types'?
不,没有内置方法可以根据数据中的两个字段应用两个色标(标记如何在分配给它的两种颜色之间进行选择?)一种可能的方法是使用不透明度第二场的编码,这反映在标记的亮度上。对于您的示例,它可能如下所示:
opacity='type:N'