2024-10-02 02:30:17 发布
网友
有没有办法增加六边形的相对大小pyplot.hexpin根据他们的频率? 我只能看到binsize的关键字参数,这会影响十六进制的数量,但不会影响它们的大小。在
但是在this article(在标题“多元六边形装箱”下大约2/3英寸)中,它讨论了绘制大小与计数成比例的六边形,以便更清楚地观察趋势(见以下图片,摘自那篇文章)
我是否错过了一个允许这样做的关键字参数?在
谢谢!在
对于所讨论的图,使用六边形分块没有任何优势,因为六边形有不同的大小,因此不允许在整个绘图中进行一致的分块。但是,您可以使用一个恒定的binning,并且只收缩没有最大值的单元格。在
import matplotlib.pyplot as plt from matplotlib.collections import PatchCollection from matplotlib.path import Path from matplotlib.patches import PathPatch import numpy as np; np.random.seed(42) a = np.random.rand(200,2) b = np.random.rand(200) c = np.concatenate((a,np.c_[b,b]), axis=0) fig, ax = plt.subplots() hexbin = ax.hexbin(c[:,0],c[:,1],gridsize=20, linewidth=0 ) def sized_hexbin(ax,hc): offsets = hc.get_offsets() orgpath = hc.get_paths()[0] verts = orgpath.vertices values = hc.get_array() ma = values.max() patches = [] for offset,val in zip(offsets,values): v1 = verts*val/ma+offset path = Path(v1, orgpath.codes) patch = PathPatch(path) patches.append(patch) pc = PatchCollection(patches) pc.set_array(values) ax.add_collection(pc) hc.remove() sized_hexbin(ax,hexbin) plt.show()
对于所讨论的图,使用六边形分块没有任何优势,因为六边形有不同的大小,因此不允许在整个绘图中进行一致的分块。但是,您可以使用一个恒定的binning,并且只收缩没有最大值的单元格。在
为了进行比较,可以通过散点图传送相同的信息。这段代码可能比上面的代码更直观。 ^{pr2}$
相关问题 更多 >
编程相关推荐