# Imports
#
import matplotlib.pyplot as plt
from libpysal.weights.contiguity import Queen
from libpysal import examples
import geopandas as gpd
from esda.moran import Moran_BV
from splot.esda import plot_moran_bv_simulation
#
# Load data and calculate weights
#
guerry = examples.load_example('Guerry')
link_to_data = guerry.get_path('guerry.shp')
gdf = gpd.read_file(link_to_data)
x = gdf['Suicids'].values
y = gdf['Donatns'].values
w = Queen.from_dataframe(gdf)
w.transform = 'r'
#
# Calculate Bivariate Moran
#
moran_bv = Moran_BV(x, y, w)
#
# plot
#
plot_moran_bv_simulation(moran_bv)
plt.show()
#
# customize plot
#
plot_moran_bv_simulation(moran_bv,
                         fitline_kwds=dict(color='#4393c3'))
plt.show()
