Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for a custom scale/breaks in legendgram #13

Open
lenkahas opened this issue Jun 19, 2020 · 0 comments
Open

Allow for a custom scale/breaks in legendgram #13

lenkahas opened this issue Jun 19, 2020 · 0 comments

Comments

@lenkahas
Copy link

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)
in
10 bins = 50,
11 legend_size=(0.4,0.13), # legend size in fractions of the axis
---> 12 loc = 'lower right');

in llegendgram(f, ax, y, breaks, pal, bins, clip, loc, legend_size, frameon, tick_params)
46 for c in range(k):
47 for b in range(bucket_breaks[c], bucket_breaks[c+1]):
---> 48 patches[b].set_facecolor(pl(c/k))
49 #---
50 if clip is not None:

IndexError: list index out of range

image

Maybe the solution could look a little like this

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant