bindings/pydeck-carto/examples/notebooks/carto_styles.ipynb
Render cloud data with color bins, categories and continous style.
import pydeck as pdk
import pydeck_carto as pdkc
from carto_auth import CartoAuth
carto_auth = CartoAuth.from_oauth()
pdkc.register_carto_layer()
layer = pdk.Layer(
"CartoLayer",
data="SELECT geom, pct_higher_ed FROM `cartobq.public_account.higher_edu_by_county`",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
get_fill_color=pdkc.styles.color_bins(
"pct_higher_ed", [0, 20, 30, 40, 50, 60, 70], "PinkYl"
),
get_line_color=[0, 0, 0, 100],
line_width_min_pixels=0.5,
pickable=True,
)
view_state = pdk.ViewState(latitude=38, longitude=-98, zoom=3)
tooltip = {"text": "Higher education percentage: {pct_higher_ed} %"}
pdk.Deck(
layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state, tooltip=tooltip
)
layer = pdk.Layer(
"CartoLayer",
data="SELECT geom, landuse_type FROM `cartobq.public_account.wburg_parcels`",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
get_fill_color=pdkc.styles.color_categories(
"landuse_type",
[
"Multi-Family Walk-Up Buildings",
"Multi-Family Elevator Buildings",
"Mixed Residential And Commercial Buildings",
"Parking Facilities",
"1 and 2 Family Buildings",
"Commercial and Office Buildings",
"Vacant Land",
"Public Facilities and Institutions",
"Transportation and Utility",
"Open Space and Outdoor Recreation",
"Industrial and Manufacturing",
],
"Bold",
),
get_line_color=[0, 0, 0, 100],
line_width_min_pixels=0.5,
pickable=True,
)
view_state = pdk.ViewState(latitude=40.715, longitude=-73.959, zoom=14)
tooltip = {
"html": "<b>Land use type:</b>
{landuse_type}",
"style": {
"color": "black",
"backgroundColor": "#84D2F6",
},
}
pdk.Deck(
layer,
map_style=pdk.map_styles.LIGHT,
initial_view_state=view_state,
tooltip=tooltip,
)
layer = pdk.Layer(
"CartoLayer",
data="SELECT geom, value FROM cartobq.public_account.temps",
type_=pdkc.MapType.QUERY,
connection=pdkc.CartoConnection.CARTO_DW,
credentials=pdkc.get_layer_credentials(carto_auth),
get_fill_color=pdkc.styles.color_continuous(
"value", [70, 75, 80, 85, 90, 95, 100], "Peach"
),
point_radius_min_pixels=2.5,
pickable=True,
)
view_state = pdk.ViewState(latitude=34, longitude=-98, zoom=3)
tooltip = {
"html": "<b>Temperature:</b> {value}°F",
"style": {
"color": "white",
},
}
pdk.Deck(
layer, map_style=pdk.map_styles.ROAD, initial_view_state=view_state, tooltip=tooltip
)