Altair Choropleth映射编码数据帧颜色问题

时间:2019-04-24 21:18:12

标签: python pandas altair

我正在尝试用邮政编码和温度数据创建一个县区地图,以覆盖过多县,但是在尝试对数据进行编码时,我仍然遇到Javascript错误。我查看了github支持,发现这有时会拉入数据帧是一个问题,但我也尝试使用csv文件作为数据类型。看来Q不能将temp列识别为数字了?

import altair as alt
from vega_datasets import data

counties = alt.topo_feature(data.us_10m.url, 'counties')
source = max_2007_df


alt.Chart(counties).mark_geoshape().encode(
    color='temp:Q').transform_lookup(
    lookup='zipcode',
    from_=alt.LookupData(source, 'zipcode', ['temp'])
).project(
    type='albersUsa'
).properties(
    width=500,
    height=300
)

Javascript错误:无法在'CanvasGradient'上执行'addColorStop':提供的float值是非限定的。通常,这表示图表规格中有错字。有关完整的追溯,请参见JavaScript控制台。

这是max_2007_temp df的一部分

    zipcode temp
0   1002    33.6
1   1011    31.8
2   1013    34.1
3   1098    31.9
4   1108    34.3
5   1129    34.1
6   1453    33.3
7   1545    33.5
8   1568    33.4
9   1571    32.8
10  1603    33.5
11  1604    33.8
12  1702    35.5
13  1721    35.5
14  1746    35.5
15  1752    35.5
16  1760    35.5
17  1772    34.4
18  1773    35.5
19  1776    35.5

1 个答案:

答案 0 :(得分:1)

您引用的地图数据data.us_10m没有任何邮政编码信息,因此将其连接到邮政编码上将不起作用。

如果您想记下图表,则需要找到按邮政编码而不是按县索引的地理数据源。

相关问题