pcolormesh support for masked arrays is incomplete · Issue #14327 · matplotlib/matplotlib · GitHub
Skip to content

pcolormesh support for masked arrays is incomplete #14327

Description

@efiring

Bug report

Bug summary
As noted in #8802, the pcolormesh test stages a masked array but does not use it. This is probably because masked array support is broken in PDF output with the gouraud shading option.

Code for reproduction
This is a modification of the test_axes.test_pcolormesh function:

import matplotlib.pyplot as plt
import numpy as np

def test_pcolormesh():
    n = 12
    x = np.linspace(-1.5, 1.5, n)
    y = np.linspace(-1.5, 1.5, n*2)
    X, Y = np.meshgrid(x, y)
    Qx = np.cos(Y) - np.cos(X)
    Qz = np.sin(Y) + np.sin(X)
    Qx = (Qx + 1.1)
    Z = np.hypot(X, Y) / 5
    Z = (Z - Z.min()) / Z.ptp()

    # The color array can include masked values:
    Zm = np.ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)

    fig, axs = plt.subplots(2, 3)
    kw = dict(vmin=0, vmax=1)
    for ax, zz in zip(axs, [Z, Zm]):
        ax[0].pcolormesh(Qx, Qz, zz, lw=0.5, edgecolors='k', **kw)
        ax[1].pcolormesh(Qx, Qz, zz, lw=2, edgecolors=['b', 'w'], **kw)
        ax[2].pcolormesh(Qx, Qz, zz, shading="gouraud", **kw)
    return fig

fig = test_pcolormesh()
fig.savefig('test_pcolormesh.png')
fig.savefig('test_pcolormesh.pdf')

Actual outcome
The pdf (converted to a png for display here) is black in the masked region with gouraud shading:
test_pcolormesh_from_pdf
but the png is as expected.
test_pcolormesh

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions