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

ENH: mapclassify plot legend as discrete colorbar #2239

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

TLouf
Copy link
Contributor

@TLouf TLouf commented Nov 27, 2021

fixes #2154

This entails a change in the fmt keyword to format tick labels, as colorbars' tick labels have been formatted with old-style formats (like "%.3f"), until the very recent matplotlib/matplotlib/pull/21542. By the way I wonder if it is desirable to keep "%.2f" as default formatting, or to rather not provide one.

I left a TODO about adding a legend entry for geometries with missing data, which I think would be easier to implement in #2012 once this one is in.

Example output:

import geopandas
from geopandas.datasets import get_path
world = geopandas.read_file(get_path('naturalearth_lowres'))
world.plot(column="pop_est", scheme="BoxPlot", legend=True)

output

@TLouf TLouf changed the title ENH: Mapclassify colorbar ENH: mapclassify plot legend as discrete colorbar Nov 27, 2021
@martinfleis
Copy link
Member

I personally like this change but I think it needs a wider discussion as it is essentially a breaking change. I think that in future, we should default to colorbar but I am not sure that we should do that abruptly, so maybe some transitional period would be helpful.

And I think that we should make sure that colorbar is not larger than the plot itself.

@Cloudiver
Copy link

I totally agree with @TLouf's suggestion. In many research paper, when different areas are distinguished by various colors, they are usually discrete colorbar, in order to highlight the difference because of continuous colorbar are not easy to read specific values. In other cases it may be to show the overall trend between regions, in this case a continuous colorbar is usually used.

Overall, I wonder if it's possible to have this feature as an optional parameter to plot instead of suddenly being the default colorbar.

@TLouf
Copy link
Contributor Author

TLouf commented Mar 5, 2022

I agree with the optional parameter, I restored the historical behaviour and set it as default. A colorbar can be generated by passing as_cbar=True in legend_kwds.

And I think that we should make sure that colorbar is not larger than the plot itself.

Personally I don't think so, this would imply using AxesDivider for instance, which also has its keyword arguments. So instead of setting an arbitrary default I'd go with matplotlib's, although it results in this height issue when the aspect ratio is not equal to 1. Then it'd be up to the user, as in matplotlib, to create a cax of their own using AxesDivider or something else.

@Yimsun97
Copy link

I am recently working on the discrete colorbar in my research program but I am no expert in the underlying implementation and combination of geopandas with matplotlib. I also find that the gridded maps with the same or different colorbar(s) are widely used in many papers. Will the geopandas offer options for flexible colorbar creation (e.g. the single colorbar for all subplots and one colorbar for each subplot) in the future? I came up with a workaround script by using the "UserDefined" scheme with self-defined colorbar, but it may not be applicable for general cases. P.S. I am a fan of geopandas and would like to hear about update on this functionality.

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

Successfully merging this pull request may close these issues.

ENH: mapclassify plots legend as colorbar
4 participants