简体   繁体   English

Requite 有助于在 Altair choropleth 中进行着色

[英]Requite helps shading in Altair choropleth

I would like to shade in the non-highlighted items below too but I am struggling to find the correct method.我也想在下面未突出显示的项目中添加阴影,但我正在努力寻找正确的方法。 I essentially want everything grey or any other set colour, except for the Boroughs highlighted..我基本上想要所有灰色或任何其他固定颜色,除了突出显示的自治市镇..

import altair as alt
from vega_datasets import data
boroughs = alt.topo_feature(data.londonBoroughs.url, 'boroughs')
centroids = data.londonCentroids.url

background = alt.Chart(boroughs).mark_geoshape(
    stroke='white',
    strokeWidth=1
).encode(
    color='IncidentDate:Q'
).transform_lookup(lookup = 'id',
    from_ = alt.LookupData(top_10v2,'Borough',['IncidentDate'])).properties(
    width=700,
    height=500
)

labels = alt.Chart(centroids).mark_text().encode(
    longitude='cx:Q',
    latitude='cy:Q',
    text='bLabel:N',
    size=alt.value(8),
    opacity=alt.value(0.6)
).transform_calculate(
    "bLabel", "indexof (datum.name,' ') > 0  ? substring(datum.name,0,indexof(datum.name, ' ')) : datum.name"
)


lines = alt.Chart(boroughs).mark_geoshape(
    filled=False,
    strokeWidth=1
).encode(color=alt.value('#eee'))

background+labels+lines

在此处输入图像描述

You have an undefined variable in your example ( top_10v2 ), so I can't test it, but you should be able to use something like this for you color encoding of the background chart:您的示例中有一个未定义的变量( top_10v2 ),所以我无法对其进行测试,但您应该能够使用类似这样的东西来对背景图表进行颜色编码:

color=alt.condition('datum.IncidentDate !== null', 'IncidentDate:Q', alt.value('lightgray'))

This should work if the white states have missing values, more examples in this question Dealing with missing values / nulls in Altair choropleth map如果白色状态有缺失值,这应该有效,这个问题中的更多示例处理 Altair choropleth map 中的缺失值/空值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM