如何在 Altair 图表上绘制闭合多边形

how to draw closed polygon on Altair chart

如何在 Altair 图表上绘制闭合多边形?

这不...谢谢。

import pandas as pd
import altair as alt


end_points = pd.DataFrame(
    dict(
        NEU=[0, 1, 0.3, 0],
        DEN=[2.65, 1, 2.5, 2.65],
    )
)


alt.Chart(end_points).mark_line().encode(
    alt.X("NEU"),
    y=alt.Y("DEN", scale=alt.Scale(domain=[3, 0])),
)

除非另有说明,否则 Altair 在绘制线条之前按 x 值对数据进行排序。如果您想要自定义订单,可以使用 order 渠道,如 Lines With Custom Paths 示例所示:

import pandas as pd
import altair as alt

end_points = pd.DataFrame(
    dict(
        NEU=[0, 1, 0.3, 0],
        DEN=[2.65, 1, 2.5, 2.65],
    )
)

alt.Chart(end_points.reset_index()).mark_line().encode(
    alt.X("NEU"),
    y=alt.Y("DEN", scale=alt.Scale(domain=[3, 0])),
    order='index'
)