Pydeck 工具提示格式数字
Posted
技术标签:
【中文标题】Pydeck 工具提示格式数字【英文标题】:Pydeck tooltip format numbers 【发布时间】:2021-04-16 02:34:20 【问题描述】:有谁知道如何编辑 pydeck 图的工具提示部分。具体来说,我想改变
html 部分中的mrt_distance
以整数形式显示,以逗号表示千位。例如,2143.45 meters
应显示为 2,143 meters
。
import pandas as pd
import pydeck as pdk
DATA_URL = "https://raw.githubusercontent.com/ajduberstein/geo_datasets/master/housing.csv"
df = pd.read_csv(DATA_URL)
view = pdk.data_utils.compute_view(df[["lng", "lat"]])
view.pitch = 75
view.bearing = 60
column_layer = pdk.Layer(
"ColumnLayer",
data=df,
get_position=["lng", "lat"],
get_elevation="price_per_unit_area",
elevation_scale=100,
radius=50,
get_fill_color=["mrt_distance * 10", "mrt_distance", "mrt_distance * 10", 140],
pickable=True,
auto_highlight=True,
)
tooltip =
"html": "<b>mrt_distance</b> meters away from an MRT station, costs <b>price_per_unit_area</b> NTD/sqm",
"style": "background": "grey", "color": "white", "font-family": '"Helvetica Neue", Arial', "z-index": "10000",
r = pdk.Deck(
column_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style=pdk.map_styles.SATELLITE,
)
r.to_html("column_layer.html")
【问题讨论】:
【参考方案1】:目前,您必须在输入数据中创建一个单独的字段,该字段是格式正确的字符串,例如,
df['formatted_distance'] = df['mrt_distance'].apply(lambda d: f'round(d, 2):,')
然后您可以在工具提示中按名称提及此列。
【讨论】:
以上是关于Pydeck 工具提示格式数字的主要内容,如果未能解决你的问题,请参考以下文章