在创建两个matplotlib.pyplot hexbin图之间的差异映射时,我遇到了一个问题,这意味着首先获取每个对应hexbin的值差异,然后创建一个差异hexbin映射。
为了给出一个简单的例子,在这里,假设地图1中一个hexbin的值是3,而映射2中相应的hexbin值是2,我想要做的是先得到差值3-2=1,然后把它绘制成一个新的六宾映射,即差分映射,在与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>

发布于 2015-12-14 10:11:22
可以使用h=hexbin()从h.get_values()获取值,并使用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()

https://stackoverflow.com/questions/34255328
复制相似问题