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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9b911e3
Merge pull request #21 from earthlab/master
nkorinek Jun 27, 2019
55de047
Merge pull request #22 from earthlab/master
nkorinek Jul 9, 2019
fd6a17d
Merge pull request #23 from earthlab/master
nkorinek Jul 18, 2019
c577c1b
Merge pull request #24 from earthlab/master
nkorinek Jul 23, 2019
ff32f45
Merge pull request #26 from earthlab/master
nkorinek Aug 20, 2019
9b5bf76
Merge pull request #27 from earthlab/master
nkorinek Aug 29, 2019
64e21fc
Merge pull request #28 from earthlab/master
nkorinek Sep 3, 2019
3496c56
Merge pull request #29 from earthlab/master
nkorinek Sep 17, 2019
1d2a61c
Merge pull request #30 from earthlab/master
nkorinek Oct 17, 2019
b7882a6
Merge pull request #31 from earthlab/master
nkorinek Oct 24, 2019
a5b62c2
Merge pull request #32 from earthlab/master
nkorinek Oct 29, 2019
d0e35e2
Merge pull request #33 from earthlab/master
nkorinek Nov 7, 2019
b38aa9f
Merge pull request #34 from earthlab/master
nkorinek Feb 18, 2020
8668a7c
Merge pull request #35 from earthlab/master
nkorinek Mar 10, 2020
a5c86bf
Merge pull request #36 from earthlab/master
nkorinek Mar 25, 2020
98c8862
Merge branch 'master' of https://github.com/earthlab/earthpy
nkorinek Mar 25, 2020
a18bacb
Merge pull request #37 from earthlab/master
nkorinek Mar 31, 2020
5ffcfb9
Merge pull request #38 from earthlab/master
nkorinek Apr 27, 2020
86d13c0
Merge pull request #39 from earthlab/master
nkorinek Apr 30, 2020
a7d53bb
Merge branch 'master' of https://github.com/earthlab/earthpy
nkorinek May 22, 2020
a42c005
Merge branch 'master' of https://github.com/earthlab/earthpy
nkorinek Jun 11, 2020
8fe046e
Merge branch 'master' of https://github.com/earthlab/earthpy
nkorinek Jun 12, 2020
79c4378
Merge branch 'master' of https://github.com/nkorinek/earthpy
nkorinek Jun 12, 2020
602d7a8
Merge branch 'master' of https://github.com/earthlab/earthpy
nkorinek Jun 19, 2020
3e12b74
Modified colorbar function to be compatible with geodataframes
nkorinek Jun 19, 2020
74fc601
Added test for update
nkorinek Jun 19, 2020
91d1e8b
small change. does ci build
Aug 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`
Unreleased
----------

- Modified `ep.colorbar()` to work with GeoDataFrame plots (@nkorinek, #557)

0.9.2
-----

Expand Down
10 changes: 8 additions & 2 deletions earthpy/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import earthpy.spatial as es


def colorbar(mapobj, size="3%", pad=0.09):
def colorbar(mapobj, size="3%", pad=0.09, return_cax=False):
"""Adjust colorbar height to match the matplotlib axis height.

NOTE: This function requires matplotlib v 3.0.1 or greater or v 2.9 or
Expand All @@ -31,6 +31,9 @@ def colorbar(mapobj, size="3%", pad=0.09):
The percent width of the colorbar relative to the plot.
pad : int (default = 0.09)
The space between the plot and the color bar.
return_cax : bool (default = False)
Boolean to return the cax created before it is applied to the axis.
Can be used to help adjust colorbars on non-array plots.

Returns
-------
Expand Down Expand Up @@ -70,7 +73,10 @@ def colorbar(mapobj, size="3%", pad=0.09):
fig = ax.figure
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size=size, pad=pad)
return fig.colorbar(mapobj, cax=cax)
if return_cax:
return cax
else:
return fig.colorbar(mapobj, cax=cax)


def _plot_image(
Expand Down
9 changes: 9 additions & 0 deletions earthpy/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ def test_colorbar_raises_value_error():
with pytest.raises(AttributeError, match="requires a matplotlib"):
ep.colorbar(list())
plt.close()


def test_colorbar_returns_cax(basic_geometry_gdf):
"""Test that colorbar works with geodataframes when cax is returned."""
f, ax = plt.subplots(figsize=(5, 5))
cb_ax = ep.colorbar(ax, return_cax=True)
im = basic_geometry_gdf.plot(ax=ax, legend=True, cax=cb_ax)
assert ax.get_position().height == im.axes.get_position().height
plt.close(f)