Skip to content

scatter not showing valid x/y points with invalid color #4354

Closed

Description

@megies

scatter plots are removing points with valid x/y coordinates but invalid color value. As colormaps have a special setting for what color should be used in case of invalid data points (used e.g. in imshow array plots) maybe these points should indeed be plotted and plotted with the specified "bad value" color.

Consider this example:

import matplotlib.pyplot as plt
from matplotlib.cm import spring
import numpy as np

spring.set_bad("k", 1)

colors = np.array([1, 3, 9, np.nan])
x = [0, 1, 2, 3]

plt.figure()
plt.imshow(colors.reshape((2, 2)), interpolation="nearest", cmap=spring)

plt.figure()
plt.scatter(x, x, s=1e4, c=colors, cmap=spring)
plt.show()

The right-hand side scatter plot is not showing the x=3, y=3, color=np.nan data point:

figure_1

Activity

  1. removed this from the milestone on Jul 31, 2015
  2. tacaswell commented on Jul 31, 2015

    @tacaswell
    Member

    punted as not a blocker for 1.5.

  3. modified the milestones: , on Oct 3, 2017
  4. ImportanceOfBeingErnest commented on May 3, 2019

    @ImportanceOfBeingErnest
    Member

    Closing, as being fixed by #12422.

    I.e. from matplotlib 3.1 on, you can use plt.scatter(...,, plotnonfinite=True) to include masked or invalid points be be colorized according to the set_bad color of the colormap.

  5. modified the milestones: needs sorting, v3.1.0 on May 3, 2019
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions