Patch3DCollection doesn't update color after calling set_color · Issue #3370 · matplotlib/matplotlib · GitHub
Skip to content

Patch3DCollection doesn't update color after calling set_color #3370

Description

@durden

I've run into an issue in 1.3.1 and the latest nightly build of the 1.4.x release candidate where calling set_color on a Patch3DCollection object doesn't seem to work. I only see the issue when using a 3D plot.

This bug was first reported here, but it seems to be unrelated.

Below is a snippet similar to what I've been trying. You can comment the lines at the bottom to alternate which version (2d or 3d) you're testing. The same mechanism works for a 2d scatter plot, but not for a 3d one.

The goal is to add a new point on each animation. Then, change all older points to a different color. It's not optimal and will constantly change the color of old points even if they've already been changed. However, it clearly demonstrates that the call to set_color doesn't have any effect even though it's a somewhat silly example.

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
import matplotlib.pylab as plt

import numpy as np

NUM_POINTS = 10
values = []

for ii in xrange(NUM_POINTS):
    values.append(np.random.random_integers(0, 500, 3))

points = []

n = 0


def two_dim_example():
    def animate(i):
        """
        Goal is to slowly add new points and have the most current point in red
        while all other points are gray
        """

        global n

        # No more animation needed
        if n >= NUM_POINTS:
            return

        # Change color of all old points
        for point in points:
            point.set_color('gray')

        x, y, z = values[n]

        point = ax2D.scatter(x, y, s=75, c='red', marker ='o')
        points.append(point)

        n += 1

    ax2D = fig1.add_subplot(111)
    ani = animation.FuncAnimation(fig1, animate, interval=500)
    plt.show()


def three_dim_example():
    def animate(i):
        """
        Goal is to slowly add new points and have the most current point in red
        while all other points are gray
        """

        global n

        # No more animation needed
        if n >= NUM_POINTS:
            return

        # Change color of all old points
        for point in points:
            point.set_color('gray')

        x, y, z = values[n]

        point = ax3D.scatter(x, y, z, s=50, c='red', marker ='o')
        points.append(point)

        n += 1

    ax3D = fig2.add_subplot(111, projection='3d')
    ani = animation.FuncAnimation(fig2, animate, interval=500)
    plt.show()


# Uncomment to see that 2d works
#fig1 = plt.figure()
#two_dim_example()

fig2 = plt.figure()
three_dim_example()

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions