Skip to content

Support masked coordinates for pcolormesh #184

@zxdawn

Description

@zxdawn

Description

Currently, the official pcolormesh doesn't support NaN or masked coordinates.
There're several solutions:

  1. Define a new function
  2. Handle the masked values manually

Steps to reproduce

import proplot as plot
import numpy as np

# Figure and sample data
state = np.random.RandomState(51423)
x = y = np.array([-10., -5., 0., 5., 10.])
data = state.rand(y.size, x.size)
fig, axs = plot.subplots()

x[:1] = np.nan
y[:1] = np.nan
axs.pcolormesh(x, y, data)

Expected behavior:
Like pcolor:
test_pcolormesh

Actual behavior:

Traceback (most recent call last):
  File "/home/xin/Desktop/test.py", line 12, in <module>
    axs.pcolormesh(x, y, data)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/proplot/ui.py", line 682, in _iterator
    result.append(func(*args, **kwargs))
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/proplot/axes/plot.py", line 3867, in wrapper
    return driver(self, func, *args, **kwargs)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/proplot/axes/plot.py", line 897, in standardize_2d
    return func(self, x, y, *Zs, **kwargs)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/proplot/axes/plot.py", line 3867, in wrapper
    return driver(self, func, *args, **kwargs)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/proplot/internals/warnings.py", line 97, in wrapper
    return func_orig(*args, **kwargs)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/proplot/axes/plot.py", line 2880, in cmap_changer
    obj = func(self, *args, **kwargs)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/matplotlib/__init__.py", line 1565, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 6093, in pcolormesh
    X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch)
  File "/home/xin/Software/miniconda3/envs/s5p/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5660, in _pcolorargs
    'x and y arguments to pcolormesh cannot have '
ValueError: x and y arguments to pcolormesh cannot have non-finite values or be of type numpy.ma.core.MaskedArray with masked values

Proplot version

0.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions