如何在两个 matplotlib hexbin 映射之间创建差异映射?
How to create a difference map between two matplotlib hexbin maps?
我在创建两个matplotlib.pyplot
hexbin
plot之间的差异图时遇到了问题,这意味着先获取每个对应的hexbin
的值差异,然后创建差异hexbin
地图。
这里举一个简单的例子说明我的问题,假设一个hexbin
在Map 1中的值为3,对应的hexbin
在Map 2中的值为2,我会喜欢做的是首先得到差异 3 – 2 = 1 然后将它绘制在一个新的 hexbin 映射中,即差异映射,在与映射 1 和映射 2 相同的位置。
我的输入代码和输出图如下。谁能给我一个解决这个问题的方法?
感谢您的宝贵时间!
In [1]: plt.hexbin(lon_origin_df, lat_origin_df)
Out[1]: <matplotlib.collections.PolyCollection at 0x13ff40610>
In [2]: plt.hexbin(lon_termination_df, lat_termination_df)
Out[2]: <matplotlib.collections.PolyCollection at 0x13fff49d0>
可以使用 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()
我在创建两个matplotlib.pyplot
hexbin
plot之间的差异图时遇到了问题,这意味着先获取每个对应的hexbin
的值差异,然后创建差异hexbin
地图。
这里举一个简单的例子说明我的问题,假设一个hexbin
在Map 1中的值为3,对应的hexbin
在Map 2中的值为2,我会喜欢做的是首先得到差异 3 – 2 = 1 然后将它绘制在一个新的 hexbin 映射中,即差异映射,在与映射 1 和映射 2 相同的位置。
我的输入代码和输出图如下。谁能给我一个解决这个问题的方法?
感谢您的宝贵时间!
In [1]: plt.hexbin(lon_origin_df, lat_origin_df)
Out[1]: <matplotlib.collections.PolyCollection at 0x13ff40610>
In [2]: plt.hexbin(lon_termination_df, lat_termination_df)
Out[2]: <matplotlib.collections.PolyCollection at 0x13fff49d0>
可以使用 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()