Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pcolormesh: shading='nearest' and non-monotonic coordinates #18317

Closed
@mathause

Description

@mathause

Bug report

Bug summary

#16258 deprecatesshading="flat" when data and coordinates have the same shape and introducesshading="nearest" which interpolates the coordinates. However, the logic to interpolate the coordinates breaks down if they are not monotonically increasing.

def_interp_grid(X):

Of course non-monotonic coordinates are a bit exotic but they make sense for geographic data.

Code for reproduction

importnumpyasnpdef_interp_grid(X):# helper for belowifnp.shape(X)[1]>1:dX=np.diff(X,axis=1)/2.X=np.hstack((X[:, [0]]-dX[:, [0]],X[:, :-1]+dX,X[:, [-1]]+dX[:, [-1]]))returnXx=np.array([1,2,0])y=np.array([1,2])X,Y=np.meshgrid(x,y)_interp_grid(X)

Actual outcome

Results in

array([[0.5,1.5,1. ,-1. ],       [0.5,1.5,1. ,-1. ]])

While having cooridinates[1, 2, 0] may seem just as wrong as coordinates[0.5, 1.5, 1, -1] the latter can cause some real-world problems in conjunction with cartopy (SciTools/cartopy#1638):

shading_rasm_both

Expected outcome

  • A warning for non-monotonic data
  • A convenient option to restore the old behaviour, e.g.shading="drop"

cc@greglucas

Matplotlib version

  • Operating system: Linux Mint
  • Matplotlib version: '3.3.1'
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.8
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp