我看过有关在 matplotlib 中绘制两个 hexbin 映射之间差异的帖子。除了 Plotly hexbin 地图箱形图,我找不到任何执行相同过程的东西。如果我有两个单独的 hexbin 子图
(t, y)
,是否可以生成一个减去 t
和 y
之间的差异的图?
import pandas as pd
import plotly.express as px
import plotly.graph_objs as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots
data = pd.DataFrame({
'Cat': ['t','y','y','t','t','t','t','y','y','y','t','y'],
'LAT': [5,6,7,5,6,7,5,6,7,5,6,7],
'LON': [10,11,12,10,11,12,10,11,12,10,11,12],
})
data = pd.concat([data]*5)
df_t = data[data['Cat'] == 't']
df_y = data[data['Cat'] == 'y']
fig = make_subplots(
rows = 2,
cols = 1,
subplot_titles = ('t', 'y'),
specs = [[{"type": "choroplethmapbox"}], [{"type": "choroplethmapbox"}]],
vertical_spacing = 0.05,
horizontal_spacing = 0.05
)
fig2 = ff.create_hexbin_mapbox(data_frame=df_t,
lat="LAT", lon="LON",
nx_hexagon=5,
opacity=0.5,
labels={"color": "Point Count"},
mapbox_style='carto-positron',
)
fig3 = ff.create_hexbin_mapbox(data_frame=df_y,
lat="LAT", lon="LON",
nx_hexagon=5,
opacity=0.5,
labels={"color": "Point Count"},
mapbox_style='carto-positron',
)
fig.add_trace(fig2.data[0], row=1,col=1)
fig.update_mapboxes(zoom=4, style='carto-positron')
fig.add_trace(fig3.data[0], row=2,col=1)
fig.update_mapboxes(zoom=4, style='carto-positron')
fig.update_layout(height=600, margin=dict(t=20,b=0,l=0,r=0))
fig.show()
预期输出:
左下角的
t
有 15 分,而 y
有 5 分。所以这总计 10。中间的分格有 10 分,所以结果为 0。右上角有 5 分,t
和y
15,来到-10。但我会将vmin
设置为0以确保没有负值。