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

Pass locator argument to matplotlib when calling plot.contourf #4787

Open
iuryt opened this issue Jan 10, 2021 · 3 comments
Open

Pass locator argument to matplotlib when calling plot.contourf #4787

iuryt opened this issue Jan 10, 2021 · 3 comments

Comments

@iuryt
Copy link

iuryt commented Jan 10, 2021

Is your feature request related to a problem? Please describe.
Everytime I have to do a contourf I need to call it from matplotlib directly because locator argument is not passed from xarray.plot.contourf to matplotlib.

Describe the solution you'd like
Being ds a xarray.DataArray, I want to have the behaviour described here when passing locator = ticker.LogLocator() to ds.plot.contourf.

Describe alternatives you've considered
I usually have to do plt.contourf(ds.dim_0,ds.dim_1,ds.values,locator = ticker.LogLocator()).

@dcherian
Copy link
Contributor

ah this is to decide what the levels are

We'll have to pass it down to here and make appropriate modifications:

xarray/xarray/plot/utils.py

Lines 272 to 281 in 8ff8113

if is_scalar(levels):
if user_minmax:
levels = np.linspace(vmin, vmax, levels)
elif levels == 1:
levels = np.asarray([(vmin + vmax) / 2])
else:
# N in MaxNLocator refers to bins, not ticks
ticker = mpl.ticker.MaxNLocator(levels - 1)
levels = ticker.tick_values(vmin, vmax)
vmin, vmax = levels[0], levels[-1]

PR welcome!

@iuryt
Copy link
Author

iuryt commented Jan 10, 2021

I can tackle this one, if no one does that before, I just have to separate a time in my week schedule for open-source projects.

@dcherian
Copy link
Contributor

@iuryt you could also create levels manually using the locator you like and pass that. That seems better than adding yet another kwarg to our plotting functions.

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

No branches or pull requests

3 participants