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

Vector colorbar compatibility #572

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

Conversation

nkorinek
Copy link
Member

@nkorinek nkorinek commented Jun 19, 2020

closes #557

Updated the ep.colorbar function to work with GeoDataFrame plots. This was a bit tricky, and I'm not sure this is the exact way we want to implement this, so feedback would be greatly appreciated @lwasser .

There are two ways I've figured out to make this work, but neither of them is ideal, so I thought I'd ask for input. I went with what I thought was the simpler way, but wasn't sure if there was a better way.

The way GeoPandas does colorbars is just by setting legend=True in the plot() function. To adjust the colorbar, you can give it a cax argument, which will implement the scale and pad arguments we have in our ep.colorbar() function.

In the ep.colorbar() function, we create a cax object and assign it to the figure. The problem is, this assumes that the object that was passed into the ep.colorbar() is what matplotlib calls a ScalarMappable, so like an array or a contour map is a ScalarMappable. A GeoDataFrame is not inheritely a ScalarMappable like numpy arrays are, so we can do one of two things. We can either make the function have an argument to return the cax before it's applied to the figure and then that can be used in gpd.plot(), which is what I did.

The other way would be to create a ScalarMappable in the function for the plot. This needs a cmap and a norm object for the map. That seemed like a lot of information to get/create in the function, so I avoided this solution.

The return cax option does change how the function is implemented a little. See below for how it changes implementation.

f, ax1 = plt.subplots(figsize=(10,6))

cax_plot = ep.colorbar(ax1, return_cax=True)

countries.plot(column='POP_EST', ax=ax1, cmap="viridis", legend=True, cax=cax_plot)

plt.show()

nkorinek and others added 26 commits June 27, 2019 10:03
Updating from EarthPy master
Updating from earthpy repo
Fixed the last two vignettes so that their thumbnails work. (earthlab#407)
Modis data clarification and CI fixes (earthlab#497)
Update sphinx_gallery from 0.5.0 to 0.6.2 (earthlab#531)
@nkorinek
Copy link
Member Author

@lwasser this pr is failing CI because I'm using gdf.plot() to test the new functionality, since that's what we made the functionality for. However, descartes is not installed on the earthpy environment, so I can't use that function in the tests. Thoughts?

@lwasser
Copy link

lwasser commented Jul 23, 2020

hey @ravi5175 just checking in. did you review this PR or are you just practicing your skills? generally PRs are reviewed by maintainers on OS projects.

Base automatically changed from master to main February 1, 2021 23:49
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

Successfully merging this pull request may close these issues.

Colorbar only works for raster plots
3 participants