如何在两个matplotlib hexbin映射之间创建差异映射?

2024-10-02 06:31:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我在创建两个matplotlib.pyplothexbin图之间遇到了一个问题,这意味着首先获得每个对应的hexbin的值差,然后创建一个差hexbin映射。在

为了给我的问题举一个简单的例子,假设地图1中的hexbin的值是3,而在地图2中对应的hexbin的值是2,我要做的是首先得到差值3–2=1,然后在一个新的六边形图中绘制,即差分图,在与地图1和地图2相同的位置。在

我的输入代码和输出图如下。有谁能给我一个解决这个问题的办法吗?在

谢谢你的时间!在

In [1]: plt.hexbin(lon_origin_df, lat_origin_df)
Out[1]: <matplotlib.collections.PolyCollection at 0x13ff40610>

enter image description here

^{pr2}$

enter image description here


Tags: 代码indfmatplotlib时间地图绘制差分
1条回答
网友
1楼 · 发布于 2024-10-02 06:31:58

可以使用h.get_values()h=hexbin()获取值,并使用h.set_values()设置值,这样您就可以创建一个新的hexbin,并将其值设置为其他两个值之间的差。例如:

import numpy as np
import matplotlib.pylab as pl

x  = np.random.random(200)
y1 = np.random.random(200)
y2 = np.random.random(200)

pl.figure()
pl.subplot(131)
h1=pl.hexbin(x, y1, gridsize=3, vmin=0, vmax=40, cmap=pl.cm.RdBu_r)
pl.colorbar()

pl.subplot(132)
h2=pl.hexbin(x, y2, gridsize=3, vmin=0, vmax=40, cmap=pl.cm.RdBu_r)
pl.colorbar()

pl.subplot(133)
# Create dummy hexbin using whatever data..:
h3=pl.hexbin(x, y2, gridsize=3, vmin=-10, vmax=10, cmap=pl.cm.RdBu_r)
h3.set_array(h1.get_array()-h2.get_array())
pl.colorbar()

enter image description here

相关问题 更多 >

    热门问题