我在创建两个 matplotlib.pyplot 之间的差异图时遇到了问题hexbin plots,意思是获取每个对应hexbin的值差先而后创差异hexbin map 。
在这里举一个我的问题的简单例子,说一个的值hexbin Map 1中的值为3,对应的hexbin的值为在 Map 2 中是 2,我想做的是首先得到差异 3 – 2 = 1,然后将其绘制在一个新的 hexbin map 中,即差异 map ,在与 map 1 和 map 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()
