-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve legend for management map (and others) #308
Comments
After a check, this requires a refactoring of the
Note this will also solve the current duplicate loading of the system tables in the different submodules. Once the system tables are accessible in the class to the plot method, the following snippet illustrates how the discrete colormap with labels can be created (code can be integrated in the .plot method): import numpy as np
import pandas as pd
import matplotlib as mpl
key = "acidity" # or management, seepage,...
# custom mapping table to extract codes/labels from the system tables
mapping = {"acidity": {"code": "acidity", "labels": "zuurgraadklasse_bodem"},
"inundation": {"code": "inundation", "labels": "description"},
"management": {"code": "code", "labels": "management"},
"seepage": {"code": "seepage", "labels": "description"},
"nutrient_level": {"code": "code", "labels": "nutrient_level"},
"seepage": {"code": "seepage", "labels": "description"},
"soil_code": {"code": "soil_code", "labels": "description"}, # ! not consistent soil_code versus soil_codes
}
ct_table = pd.read_csv(f"../niche_vlaanderen/system_tables/{key}.csv") # refactor so this is extracted from niche-class
ct_table = ct_table.sort_values(by=mapping[key]["code"])
# Define bounds/norm for cmap
cmap = mpl.cm.viridis
bounds = np.concatenate([ct_table[mapping[key]["code"]].values,
np.array([ct_table[mapping[key]["code"]].values.max() + 1])]) - 0.5
norm = mpl.colors.BoundaryNorm(bounds, cmap.N, extend='neither')
# create plot
fig, ax = plt.subplots()
full.plot(key, ax=ax)
# add custom colorbar
cbar = fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap),
cax=fig.axes[1], ticks=ct_table[mapping[key]["code"]].values)
cbar.set_ticklabels(ticklabels=ct_table[mapping[key]["labels"]].values) |
Note, the |
Rather than showing a scalebar, if the input data contains distinct classes with a lookup table (such as management), it would be better to show these values in the legend.
The text was updated successfully, but these errors were encountered: