使用Hexbin Matplotlib绘制Osmnx边缘

时间:2020-07-26 21:24:44

标签: python matplotlib networkx osmnx

给出了我现在提供的代码

city = 'France, Paris'
G = ox.graph_from_place(city, network_type='drive', simplify=True)

G_nx = nx.relabel.convert_node_labels_to_integers(G)
nodes, edges = ox.graph_to_gdfs(G_nx, nodes=True, edges=True) 



x_1 = []
y_1 = []
lista_nodos = [i for i in range(len(G_nx.nodes))]
for n in lista_nodos:
    x_1.append(nodes['x'].iloc[n])
    y_1.append(nodes['y'].iloc[n])


fig, ax = plt.subplots(nrows=1, ncols=1)
fig.set_size_inches((40,30))
edges.plot(ax=ax, linewidth=0.2, edgecolor='gray')
im = ax.hexbin(x_1, y_1, C=r_medio, gridsize=100, bins=None, mincnt=0, cmap = cmap, norm=norm, alpha = 1)
ax.set_axis_off()

#ax.scatter(x_1,y_1,c='w', s=10)
kwargs = {'format': '%.2f'}
cbar = fig.colorbar(im,  aspect=50, shrink=0.8, extend='both', **kwargs)
cbar.set_label('r_medio', fontsize=45)
cbar.ax.tick_params(labelsize=45)
fig.tight_layout()
fig.set_frameon(True)
fig.savefig('d.png', facecolor=fig.get_facecolor(), bbox_inches='tight')

我得到这个图:

enter image description here

这显然看起来很奇怪。就像它不在焦点上一样,我尝试过调整图形大小,但是在达到某个值之后,图像根本不会改变。

我应该看起来像这样: enter image description here

但是它不是点,而是六边形。

hexbin的颜色映射可以是任意的。hexbin中的C参数也是如此。

0 个答案:

没有答案