splot.libpysal.plot_spatial_weights¶
-
splot.libpysal.
plot_spatial_weights
(w, gdf, indexed_on=None, ax=None, figsize=(10, 10), node_kws=None, edge_kws=None, nonplanar_edge_kws=None)[source]¶ Plot spatial weights network. NOTE: Additionally plots w.non_planar_joins if libpysal.weights.util.nonplanar_neighbors() was applied.
- Parameters
- wlibpysal.W object
Values of libpysal weights object.
- gdfgeopandas dataframe
The original shapes whose topological relations are modelled in W.
- indexed_onstr, optional
Column of gdf which the weights object uses as an index. Default =None, so the geodataframe’s index is used.
- axmatplotlib axis, optional
Axis on which to plot the weights. Default =None, so plots on the current figure.
- figsizetuple, optional
W, h of figure. Default =(10,10)
- node_kwskeyword argument dictionary, optional
Dictionary of keyword arguments to send to pyplot.scatter, which provide fine-grained control over the aesthetics of the nodes in the plot. Default =None.
- edge_kwskeyword argument dictionary, optional
Dictionary of keyword arguments to send to pyplot.plot, which provide fine-grained control over the aesthetics of the edges in the plot. Default =None.
- nonplanar_edge_kwskeyword argument dictionary, optional
Dictionary of keyword arguments to send to pyplot.plot, which provide fine-grained control over the aesthetics of the edges from weights.non_planar_joins in the plot. Default =None.
- Returns
- figmatplotlip Figure instance
Figure of spatial weight network.
- axmatplotlib Axes instance
Axes in which the figure is plotted.
Examples
Imports
>>> from libpysal.weights.contiguity import Queen >>> import geopandas as gpd >>> import libpysal >>> from libpysal import examples >>> import matplotlib.pyplot as plt >>> from splot.libpysal import plot_spatial_weights
Data preparation and statistical analysis
>>> gdf = gpd.read_file(examples.get_path('map_RS_BR.shp')) >>> weights = Queen.from_dataframe(gdf) >>> wnp = libpysal.weights.util.nonplanar_neighbors(weights, gdf)
Plot weights
>>> plot_spatial_weights(weights, gdf) >>> plt.show()
Plot corrected weights
>>> plot_spatial_weights(wnp, gdf) >>> plt.show()