Altair:带有笔触标记的折线图

时间:2020-03-24 19:35:05

标签: python data-visualization vega-lite altair

我正在尝试在Altair中创建带有点标记的折线图。我正在使用Altair文档中的multi-series line chart example,并尝试将其与Vega-Lite文档中的line chart with stroked point markers example结合使用。

我很困惑的是如何处理'mark_line'参数。从Vega示例中,我需要使用“ point”,然后将“ filled”设置为False。

  "mark": {
    "type": "line",
    "point": {
      "filled": false,
      "fill": "white"
    }
  },

我将如何在Altair中应用它?我发现将'point'设置为'True'或'{}'会添加一个点标记,但是对于如何使填充起作用却感到困惑。

source = data.stocks()

alt.Chart(source).mark_line(
    point=True
).encode(
    x='date',
    y='price',
    color='symbol'
)

2 个答案:

答案 0 :(得分:3)

您可以将更多信息传递给point参数,类似于如何指定vega-lite。

import altair as alt
from vega_datasets import data

source = data.stocks()

alt.Chart(source).mark_line(
    point={
      "filled": False,
      "fill": "white"
    }
).encode(
    x='date',
    y='price',
    color='symbol'
)

enter image description here

答案 1 :(得分:3)

您始终可以将原始的vega-lite字典传递给Altair中的任何属性:

    Amazo uy,0123,4213,5424

或者您可以检查source = data.stocks() alt.Chart(source).mark_line( point={ "filled": False, "fill": "white" } ).encode( x='date', y='price', color='symbol' ) 的文档字符串,看看它是否期望指向mark_line()并使用Python包装器:

OverlayMarkDef()