Skip to content

changed method on PathCollection may revert set_color #13131

Open
@stippingerm

Description

@stippingerm

Bug report

Bug summary

When a PathCollection is created (e.g. by a scatter plot) using an array of scalars to be colormapped on it then the changed() method reverts the effect of previously issued set_facecolor command thus set_facecolor does not work as expected. (As a consequence set_color() deos not work as expected either.)

Code for reproduction

import matplotlib.pyplot as plt

def make_fig():
    fig, ax = plt.subplots(1,2, figsize=(6,2))
    sc0 = ax[0].scatter([0,0,1],[0,1,0], c=(1,2,3), linewidths=3, alpha=None)
    ax[0].set_title('Colormapped scalar')  # underlying ScalarMappable mixin is used
    sc1 = ax[1].scatter([0,0,1],[0,1,0], c=['r','g','b'], linewidths=3, alpha=None)
    ax[1].set_title('Indiv color definition')
    return fig, ax, sc0, sc1

fig, ax, sc0, sc1 = make_fig()
sc0.set_facecolor([[1, 0, 0, 0.1],[1, 0, 0, 0.5],[1, 0, 0, 0.9]])
sc0.changed()  # unexpected behavior here
sc1.set_facecolor([[1, 0, 0, 0.1],[1, 0, 0, 0.5],[1, 0, 0, 0.9]])
sc1.changed()  # unexpected behavior here

Actual outcome

mpl_color_bug1

Expected outcome

The same shades of red shall appear on the left panel that are displayed on the right.

Note: without the changed() calls everything is OK. set_facecolor correctly changes both face and edge color and alpha for individual colors and for colormapped scalar too.
But then, the changed() method reverts all changes for colormapped scalars Most probably set_facecolor does not correctly update some property telling that new colors are not derived from scalar values anymore.

Additional nuissances

fig, ax, sc0, sc1 = make_fig()
sc0.set_color([[1, 0, 0, 0.1],[1, 0, 0, 0.5],[1, 0, 0, 0.9]])
sc0.changed()
sc1.set_color([[1, 0, 0, 0.1],[1, 0, 0, 0.5],[1, 0, 0, 0.9]])
sc1.changed()
# fig.canvas.draw_idle()  # does not help

mpl_color_bug2

In the above settings, set_color changes both face and edge color together with alpha for individual colors and edge color together with alpha for colormapped scalar too.
But then, the changed() method reverts face color for colormapped scalars. Face color should not be reverted by calling changed().

Matplotlib version

  • Operating system: Windows
  • Matplotlib version: 3.0.2
  • Python version: 3.6.7 |Anaconda custom (64-bit)| (default, Dec 10 2018, 20:35:02) [MSC v.1915 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions