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

earthpy.plot.plot_bands method ignores ax keyword argument if raster has multiple bands #796

Open
ahasha opened this issue Nov 18, 2022 · 2 comments

Comments

@ahasha
Copy link

ahasha commented Nov 18, 2022

Describe the bug
earthpy.plot.plot_bands method ignores ax keyword argument if raster has multiple bands

To Reproduce
Steps to reproduce the behavior:

If raster is an array with raster.ndim > 2 and raster.shape[0] > 1, then the ax keyword
argument has no effect and the plot_bands method produces a new axes array. The user has
no access to the figure object to customize the plot.

import earthpy.plot as ep
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 1)
ep.plot_bands(raster, ax=axs)

will produce an output that looks like

image

Expected behavior

Ideally, if an axis grid consistent with the number of bands is passed in the ax keyword argument, the method would use these axes objects as expected. If this is not feasible, an error message indicating that the ax keyword is not supported when multi-band arrays are provided is needed to avoid confusion.

**What Operating System Are you Running? **

  • Mac
ahasha added a commit to ahasha/earthpy that referenced this issue Nov 18, 2022
* Added logic to earthpy.plot.plot_bands to validate dimensions of
  ax array, if provided, when raster array is multiband.
  Raises a ValueError if the provided axes array is smaller
  than the number of bands.
* Added a test for the success and failure states.
@ahasha
Copy link
Author

ahasha commented Nov 18, 2022

I have a branch in my fork with a potential solution to this issue: https://github.com/ahasha/earthpy/tree/issue_796

Please let me know if a PR would be welcome. Thanks!

@nkorinek
Copy link
Member

nkorinek commented Dec 2, 2022

Hey @ahasha! Seeing this now, the solution on your branch looks awesome. A PR would be very welcome, might ask for some changes before I merge it but go ahead and get it started!

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

2 participants