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

Allow passing axis kwargs to plot #4020

Merged
merged 34 commits into from Jul 2, 2020

Conversation

raphaeldussin
Copy link
Contributor

facecolor can be passed in plot kwargs but has no effect and does not raise exception.
PR fixes the problem.

@mathause
Copy link
Collaborator

mathause commented May 3, 2020

facecolor is a valid argument for several of the plotting functions (e.g. pcolormesh). The better approach here would be to thread subplot_kws

subplot_kws=None,

through to get_axis

def get_axis(figsize, size, aspect, ax):

in all the right places (+ tests). This would also solve #3169.

@pep8speaks
Copy link

pep8speaks commented May 16, 2020

Hello @raphaeldussin! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-07-01 15:16:02 UTC

@raphaeldussin
Copy link
Contributor Author

raphaeldussin commented May 16, 2020

apologies for the many commits, testing the test was a bit difficult.

@raphaeldussin
Copy link
Contributor Author

an example of using cartopy and a custom background:

Screenshot 2020-05-16 20 26 52

@raphaeldussin
Copy link
Contributor Author

@mathause is there anything I can do to make this PR move forward?
I fixed the conflict that happened since my last commit. failed tests here seem independent from PR.

thanks!

@raphaeldussin
Copy link
Contributor Author

all tests passed!

Copy link
Collaborator

@keewis keewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for being patient, @raphaeldussin. I'm not too familiar with the plotting code, but I have a few general suggestions.

xarray/plot/utils.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/plot/utils.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
@raphaeldussin
Copy link
Contributor Author

@keewis thank you for the review. I have implemented the proposed changes.

@keewis
Copy link
Collaborator

keewis commented Jun 23, 2020

thanks, looks good to me.

@raphaeldussin
Copy link
Contributor Author

would it make sense to update the documentation here: http://xarray.pydata.org/en/stable/plotting.html#maps

the update would be:

-    ax = plt.axes(projection=ccrs.Orthographic(-80, 35))
-    air.isel(time=0).plot.contourf(ax=ax, transform=ccrs.PlateCarree())
-    ax.set_global()
+    p = air.isel(time=0).plot(projection=ccrs.Orthographic(-80, 35),
+                              transform=ccrs.PlateCarree())
+    p.axes.set_global()

     @savefig plotting_maps_cartopy.png width=100%
-    ax.coastlines()
+    p.axes.coastlines()

Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I made suggestions - the main issue I have is that you currently mix kwargs which should go to ax.plot() and subplot_kws which should go to plt.axes().

So I think your example should be:

da.plot(subplot_kws=dict(projection=ccrs.PlateCarree(), facecolor="gray"), transform=ccrs.PlateCarree(), ...)

(btw please never use this colormap in production ;-) )

xarray/plot/utils.py Outdated Show resolved Hide resolved
xarray/plot/plot.py Outdated Show resolved Hide resolved
xarray/plot/plot.py Show resolved Hide resolved
xarray/plot/plot.py Show resolved Hide resolved
xarray/plot/plot.py Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more nits from my side.

doc/plotting.rst Outdated
Comment on lines 746 to 748
p = air.isel(time=0).plot(subplot_kws=dict(projection=ccrs.Orthographic(-80, 35),
facecolor="gray"),
transform=ccrs.PlateCarree())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
p = air.isel(time=0).plot(subplot_kws=dict(projection=ccrs.Orthographic(-80, 35),
facecolor="gray"),
transform=ccrs.PlateCarree())
p = air.isel(time=0).plot(
subplot_kws=dict(projection=ccrs.Orthographic(-80, 35), facecolor="gray"),
transform=ccrs.PlateCarree(),
)

nit: formatting

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future, these kinds of formatting issues in documentation can be automatically fixed using blackdoc, see #4177.

xarray/plot/plot.py Outdated Show resolved Hide resolved
xarray/plot/plot.py Show resolved Hide resolved
xarray/plot/plot.py Outdated Show resolved Hide resolved
xarray/plot/plot.py Show resolved Hide resolved
xarray/plot/utils.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/plot/plot.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - thanks.

The "resolve conversation" button seems to have disappeared... so I cannot close the comments that are no longer relevant.

pinging @keewis @dcherian

@raphaeldussin
Copy link
Contributor Author

Looks good to me - thanks.

The "resolve conversation" button seems to have disappeared... so I cannot close the comments that are no longer relevant.

pinging @keewis @dcherian

I can see the "resolve conversation" buttons, do you want me to close them?

xarray/plot/plot.py Outdated Show resolved Hide resolved
@keewis
Copy link
Collaborator

keewis commented Jun 25, 2020

@mathause: yep, that seems to be restricted to maintainers and pull request authors, so if someone reviewed without being a maintainer they won't be able to change the resolve status of their own comments. Also, there doesn't seem to be a setting to change this.

Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @raphaeldussin. I see this is your first PR , welcome!

I apologize for the late review. Thank you for your patience.

I have some minor comments: mostly to clean up the tests you've added (for a previously untested function, so thanks!)

xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
xarray/tests/test_plot.py Outdated Show resolved Hide resolved
@dcherian dcherian changed the title fix facecolor plot Allow passing axis kwargs to plot Jun 29, 2020
@dcherian
Copy link
Contributor

this should be good to go when tests pass.

* upstream/master: (21 commits)
  fix typo in error message in plot.py (pydata#4188)
  Support multiple dimensions in DataArray.argmin() and DataArray.argmax() methods (pydata#3936)
  Show data by default in HTML repr for DataArray (pydata#4182)
  Blackdoc (pydata#4177)
  Add CONTRIBUTING.md for the benefit of GitHub
  Correct dask handling for 1D idxmax/min on ND data (pydata#4135)
  use assert_allclose in the aggregation-with-units tests (pydata#4174)
  Remove old auto combine (pydata#3926)
  Fix 4009 (pydata#4173)
  Limit length of dataarray reprs (pydata#3905)
  Remove <pre> from nested HTML repr (pydata#4171)
  Proposal for better error message about in-place operation (pydata#3976)
  use builtin python types instead of the numpy alias (pydata#4170)
  Revise pull request template (pydata#4039)
  pint support for Dataset (pydata#3975)
  drop eccodes in docs (pydata#4162)
  Update issue templates inspired/based on dask (pydata#4154)
  Fix failing upstream-dev build & remove docs build (pydata#4160)
  Improve typehints of xr.Dataset.__getitem__ (pydata#4144)
  provide a error summary for assert_allclose (pydata#3847)
  ...
@raphaeldussin
Copy link
Contributor Author

@dcherian thanks for the final fixes!

@dcherian
Copy link
Contributor

dcherian commented Jul 2, 2020

@raphaeldussin thanks for your patience here.

@dcherian dcherian merged commit 834d4c4 into pydata:master Jul 2, 2020
dcherian added a commit to dcherian/xarray that referenced this pull request Aug 16, 2020
* master:
  Add initial cupy tests (pydata#4214)
  Add 0.16.0 release summary
  New whatsnew section
  Release v0.16.0
  Minor reorg of whatsnew for 0.16.0 (pydata#4216)
  fix sphinx warnings (pydata#4199)
  pin isort (pydata#4206)
  get the colorbar label via public methods (pydata#4201)
  Bump minimum versions for 0.16 release (pydata#4175)
  Allow passing axis kwargs to plot (pydata#4020)
  Fix to_unstacked_dataset for single dimension variables. (pydata#4094)
  Improve the speed of from_dataframe with a MultiIndex (by 40x!) (pydata#4184)
  More pint compatibility: silence UnitStrippedWarnings (pydata#4163)
  Fix typo (pydata#4192)
  use the latest image of RTD (pydata#4191)
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.

None yet

5 participants