是否可以在Altair中实现数据分类方案(对于唱片图)?

发布于 2025-01-24 09:28:09 字数 1673 浏览 5 评论 0 原文

我正在使用Altair创建一个Choropleth情节功能,并希望使用不同的数据“ nofollow noreferrer”>“分类”方案对于散点标记的大小。我已经查找了 bin参数 bin transform 编码中,但尚未解决。理想情况下,我想像它们在 size 部分是相关的)

base = alt.Chart(choro_data).mark_geoshape(
    fill="lightgray",
    stroke='white',
    strokeWidth=0.1
).properties(
    width=1000,
    height=800,
    title='Safe Graph for Average Distance'
).project(
    type='albersUsa'
)

cold = alt.Chart(choro_data).mark_circle().encode(
    latitude='properties.latitude:Q',
    longitude='properties.longitude:Q',
    stroke=alt.ColorValue("black"),
    strokeWidth = alt.value(1),
    strokeOpacity = alt.condition(
        'datum.properties.recency <= 5',   ### condition value set to??
        alt.value(1), 
        alt.value(0)),
    color=alt.Color('properties.recency:Q',
                                     bin = alt.Bin(step=5),
                                     scale=alt.Scale(scheme='blues'),
                                     legend=alt.Legend(title='Week Numbers (Cold Spots)')),
    size=alt.Size('properties.total:Q', 
                  scale=alt.Scale(range=[0, 70]),
                  bin=alt.Bin(step=5),
                  legend=alt.Legend(title='Number of Time Classified as Cold/Hot Spots')),
    tooltip=display
)

base+cold

唱片情节

I am creating a choropleth plot function with Altair and want to use different data classification scheme for the size of the scatter markers. I have looked up the bin parameters and bin transform in encoding but haven't worked it out. Ideally I want to implement the classification schemes like they are in GeoPandas. Here is my current code and plot (only the size part is relevant I believe)

base = alt.Chart(choro_data).mark_geoshape(
    fill="lightgray",
    stroke='white',
    strokeWidth=0.1
).properties(
    width=1000,
    height=800,
    title='Safe Graph for Average Distance'
).project(
    type='albersUsa'
)

cold = alt.Chart(choro_data).mark_circle().encode(
    latitude='properties.latitude:Q',
    longitude='properties.longitude:Q',
    stroke=alt.ColorValue("black"),
    strokeWidth = alt.value(1),
    strokeOpacity = alt.condition(
        'datum.properties.recency <= 5',   ### condition value set to??
        alt.value(1), 
        alt.value(0)),
    color=alt.Color('properties.recency:Q',
                                     bin = alt.Bin(step=5),
                                     scale=alt.Scale(scheme='blues'),
                                     legend=alt.Legend(title='Week Numbers (Cold Spots)')),
    size=alt.Size('properties.total:Q', 
                  scale=alt.Scale(range=[0, 70]),
                  bin=alt.Bin(step=5),
                  legend=alt.Legend(title='Number of Time Classified as Cold/Hot Spots')),
    tooltip=display
)

base+cold

choropleth plot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文