Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Getting internal "MatplotlibDeprecationWarning: shading='flat' ..." #18595

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

Closed
twmacro opened this issue Sep 27, 2020 · 11 comments · Fixed by #18860
Closed

Getting internal "MatplotlibDeprecationWarning: shading='flat' ..." #18595

twmacro opened this issue Sep 27, 2020 · 11 comments · Fixed by #18860

Comments

@twmacro
Copy link

twmacro commented Sep 27, 2020

Bug report

Bug summary

I'm getting this warning:

MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3.  Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading'].  This will become an error two minor releases later.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10.0)
mat = np.random.randn(10, 10)
plt.contour(x, x, mat)

# for a solid colorbar:
cbar = plt.colorbar()
cbar.filled = True
cbar.draw_all()

Actual outcome

Python 3.8.5 (default, Sep  4 2020, 07:30:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: run ttt
ttt.py:11: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3.  Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading'].  This will become an error two minor releases later.
  cbar.draw_all()

In [2]: import matplotlib

In [3]: matplotlib.__version__
Out[3]: '3.3.1'

In [4]: quit

Expected outcome

No deprecation warning.

Matplotlib version

  • Operating system: Linux 5.3.0-64-generic Include test_text in default_test_modules #58-Ubuntu
  • Matplotlib version: 3.3.1 (I also tried 3.3.2 -- same result)
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.8.5
  • Jupyter version (if applicable):
  • Other libraries:

Matplotlib installed via conda, default channel.

@ksunden
Copy link
Member

ksunden commented Sep 27, 2020

col = self.ax.pcolormesh(*args, **kw, shading='flat')

Here is the offending line

@jklymak jklymak added this to the v3.3.3 milestone Sep 28, 2020
@jklymak
Copy link
Member

jklymak commented Sep 28, 2020

This shouldn't be too hard to fix - someone just needs to look and see how the solid colorbar is made and make the x/y the proper length....

@jklymak
Copy link
Member

jklymak commented Sep 28, 2020

OK, so its easy to fix the above to the old behaviour. However, I strongly expect the old behaviour was incorrect and dropping the color for your highest contour value. Is that OK? Your last color was basically the color of the second to last contour.

@dopplershift
Copy link
Contributor

Well, that's ok because it matches the case with filled=False. My question would be, why does this code:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10.0)
mat = np.hypot(x, x[:, None])
plt.xlim(-1, 10)
plt.ylim(-1, 10)

cntr = plt.contour(x, x, mat, levels=np.arange(13) + 0.5)

# for a solid colorbar:
cbar = plt.colorbar()
#cbar.filled = True
cbar.draw_all()

produce:
image
which only has 12 lines on the colorbar (and thus is already chopping the highest level).

@jklymak
Copy link
Member

jklymak commented Sep 28, 2020

Is that just clipping?

@dopplershift
Copy link
Contributor

Probably: len(cbar.lines[0].get_colors()) gives 13. If only I could get it to draw properly...I can never remember how to hack colorbar axes...

@jklymak
Copy link
Member

jklymak commented Sep 28, 2020

hmmmm, are the contour axes still the old style? Because the new style should allow just setting the xlim....

@dopplershift
Copy link
Contributor

Setting xlim/ylim on the colorbar only changes its size, it doesn't draw anything above 12.5 for me.

@jklymak
Copy link
Member

jklymak commented Sep 28, 2020

Yech. Curious if it ever worked or if we (prob. me) broke something?

@anntzer
Copy link
Contributor

anntzer commented Oct 5, 2020

My guess is that this comes from

self.outline.set_xy(xy)

i.e. the outline doesn't get updated when you change the axis limits. I think the outline (and patch) should instead be defined in ax.transAxes for things to work?

@jklymak
Copy link
Member

jklymak commented Oct 28, 2020

Oh hum. I spent about a week of Matplotlib time working on fixing all this, but its a pretty big architecture change. Someone should probably dive in and patch this for the contour case cited above for 3.3.3

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

Successfully merging a pull request may close this issue.

5 participants