legendgram
legendgram copied to clipboard
Allow for a custom scale/breaks in legendgram
It would be nice to also be able to use a custom scale for legendgram, in situations where the full colorbar/scale needs to be presented as well as how the data fits into it.
See example, which uses the legendgram function where pal.number is pal.n discussed in issue #12
import pandas as pd
import numpy as np
import mapclassify as mf
from matplotlib.colors import ListedColormap
import geopandas as gpd
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.DataFrame(np.random.gamma(5,5,300), columns = ['var']) # create some random data
data['var'] = (data['var']/100)-0.12 # shift is left and on small scale so it it is the same as my situation
data = data.iloc[0:265,:] # make it uneven
data.hist();
nybb_path = gpd.datasets.get_path('nybb') # get some random spatial data
boros = gpd.read_file(nybb_path)
boros.set_index('BoroCode', inplace=True)
brk = np.arange(-0.9, 0.9,0.06) # define the custom breaks
b = ListedColormap(sns.color_palette("bwr", 30).as_hex()) # get the pallette
scheme = mf.UserDefined(data['var'], bins=brk) # define the bins
fig, ax = plt.subplots(1, figsize=(10, 10))
boros.plot(column = 'Shape_Area', cmap = b, ax = ax)
ax.axis('off')
legendgram(fig,ax, data['var'], breaks = scheme.bins, pal=b, bins = 50, legend_size=(0.4,0.13), # legend size in fractions of the axis loc = 'lower right');
IndexError Traceback (most recent call last)
IndexError: list index out of range
Maybe the solution could look a little like this