stateDiagram-v2
direction LR
w:水循环
g:地下水
r:河水
p:降水
t:气温
m:其他
sgi:标准化地下水指标
spi:标准化降水指标
srsi:标准化河流水位指标
spet:蒸散量指数
state w {
g--r--p--t--m
}
g-->sgi
r-->srsi
p-->spi
t-->spet
state join <<join>>
sgi-->join
srsi-->join
spi-->join
spet-->join
m-->join
s:时间序列统计学意义
join-->s:相关性矩阵
pie title 语言分比
"Python":90
"R":10
"C/C++":20
pie title 内容分比
"算法":90
"水文学":80
"水文指标":60
"统计学度量":40
"数学":30
"时间序列":20
"数据分析、可视化":20
Altair 是一个基于 Vega 和 Vega-Lite(来自 JS)的声明式图形可视化库,而 Vega 和 Vega-Lite 又基于 D3.js。它允许将交叉地图与其他类型的图形相关联,如以下示例所示:
import altair as alt
url_geojson = 'mallorca_geoson.json'
data_geojson = alt.Data(url=url_geojson, format=alt.DataFormat(property=' features',type='jjson'))
mallorca = alt.Chart(data_geojson).mark_geoshape(stroke="gray", color="white", strokeWidth=0.5)
#D Data
coord_mask = (pluvio.COORD_X >= 2.2) & (pluvio.COORD_X <= 3.5)&\\\\
(pluvio.COORD \\\\overline{Y}>=38.\\\\theta)&(pluvio.COORD_
mallorca_pluvio = pluvio.\\\\्रoc[coord_mask, : ]
#Plots
brush = alt.selection_interval(encodings=["longitude", "latitude"], empty=False)
pluviometros = alt.Chärt(mallorca_pluvio) \\\\
.mark circle(size=50)\\\\
.encode(
longitude =' COORD X:Q',
latitude='COORD \\\\Y:Q',
tooltip=['NOMBRE:N', 'ALTITUD:Q'],
color=alt.condition(brush, alt.value("red"), alt.value("lightgray"))
) \\\\
.project("equalEarth") \\\\
.properties(width=500, height=350) \\\\
. add params(brush)
bars = alt.Chart(mallorca_pluvio) \\\\
.mark_bar() \\\\
.encode(
x=alt.X("ALTITUD:Q"),bin(extent=[0,700]),
y=" count (ALTITUD):0",
color=alt.value("steelblue")
)
left_map = mallorca + pluviometros
bars_overlay = bars.encode(color=alt.value("red")).transform_filter(brush)
right bars = alt. layer(bars, bars_overlay)
left_map | (bars + right_bars)
为简洁起见,下面仅使用 2013 年的数据为每种车辆类型生成一张图表。
import altair as alt
# Base chart
url_geojson = 'mallorca_geoson.json'
data_geojson = alt. Data(url=url_geojson, format=alt.DataFormat(property='features',type='json'))
mallorca = alt.Chart(data_geojson), mark_geoshape(stroke="gray", strokeWidth=0.2)
data = data. loc[data. year == 2013, :]
options = ["cars", "scooters", "motorbikes", "vans", "trucks"]
mallorca \\\\
.transform_lookup(
lookup="properties, neighbourhood",
from_alt.LookupData(data=data, key="municipality", fields=["municipality"] + vehic)
) \\\\
.encode(
alt.Color(alt, repeat('row'), type='quantitative'),
tooltip=["municipality:N", alt.Tooltip(alt.repeat('row'), type='quantitative')]) \\\\
.project(type="equalEarth") \\\\
.properties(width=400, height=200) \\\\
.repeat(row=options) \\\\
.resolve_scale(color='independent')
Plotly 允许以与 Altair 提供的类似交互的方式表示地图,此外还可以通过 mapbox API 访问 Carto 和 OpenStreet 地图。
import plotly.express as px
fig = px.scatter_mapbox(pluvio,
lat=pluvio. COORD Y,
lon=pluvio.COORD_X,
hover_name="NOMBRE",
hover data="ALTITUD",
mapbox_style="carto-positron",
center={"lat": 39.5, "lon": 2.85},
zoom=8)
fig.show()
下面的交互式地图与 Dash 集成,包含额外的交互,可让您探索多年来不同车辆的数量。
import json
from dash import Dash, dcc, html, Input, Output
with open('mallorca_geoson.json') as file:
mallorca_geoson = json.load(file)
app = Dash (__name__)
app.layout = html.Div([
html.H4('Vehicles per 1000 inhab.'),
html.P("Select a vehicle:"),
dcc.RadioItems(
id='mapbox-mallorca geoson-choropleth-x-vehicle',
options=["cars", "scooters", "motorbikes", "vans", "trucks"],
value="cars",
inline=True
),
dcc.Graph(id="mapbox-mallorca geoson-choropleth-x-graph"),
])
@app.callback(
Output("mapbox-mallorca_geoson-choropleth-x-graph", "figure"),
Input("mapbox-mallorca_geoson-choropleth-x-vehicle", "value"))
def display choropleth(vehicle):
fig = px.choropleth_mapbox(
data, geojson=mallorca_geoson, color=vehicle,
color continuous scale="Viridis",
locatīons="municípality",
featureidkey="properties.neighbourhood",
center={"lat": 39.5, "lon": 2.85},
zoom=7.5,
animation_frame="year"
)
fig.update_layout(
margin={"r":0,"tt":\\\\theta,"l":0,"b":0},
mapbox_accesstoken=token
)
return fig
if __name___= "__main__":
app.run_server (debug=True)
Bokeh 是一个用于创建交互式 JS 可视化的 Python 库,它不基于 D3.js。如果 Plotly 与包含 Flask Web 服务器的 Dash 集成,那么 Bokeh 则使用 Tornado Web 服务器,后者在后端使用 WebSockets。WebSockets 是有状态的且异步的。