Skip to content

Patch3DCollection doesn't update color after calling set_color #3370

Closed

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

  1. added this to the v1.4.x milestone on Aug 17, 2014
  2. modified the milestones: , v1.4.x on Feb 7, 2015
  3. tacaswell commented on Feb 7, 2015

    @tacaswell
    Member
  4. WeatherGod commented on Feb 7, 2015

    @WeatherGod
    Member

    Yeah, I am actually going over the Poly3DCollection code right now and I am
    coming up with some ideas on how to simplify the codebase across all the
    different 3d collections. Maintaining multiple arrays of things is just not
    working properly. Instead, I am thinking that a single indexing array
    should be used that would be sorted by depth, and allow accessing the
    colors, verts, offsets, etc independently.

    I will first fix the bug at hand (not this one, the Poly3DCollection one)
    and then try out my idea.

    On Sat, Feb 7, 2015 at 5:45 PM, Thomas A Caswell [email protected]
    wrote:

    attn @WeatherGod https://github.com/WeatherGod

    —
    Reply to this email directly or view it on GitHub
    #3370 (comment)
    .

  5. added a commit that references this issue on Feb 9, 2015
    baa352c
  6. WeatherGod commented on Feb 9, 2015

    @WeatherGod
    Member

    PR #4090 fixes this completely.

    On Mon, Feb 9, 2015 at 3:47 PM, Thomas A Caswell [email protected]
    wrote:

    Assigned #3370 #3370 to
    @WeatherGod https://github.com/WeatherGod.

    —
    Reply to this email directly or view it on GitHub
    #3370 (comment).

  7. added a commit that references this issue on Dec 1, 2015
    1c3daac
  8. WeatherGod commented on Dec 1, 2015

    @WeatherGod
    Member

    I am so sorry for forgetting about the bugfix I had for this. I have cherry-picked it into its own PR and targeting it for the 2.1 release (since it is technically an API addition).

  9. durden commented on Dec 9, 2015

    @durden
    Author

    @WeatherGod No problem. Thanks for the update!

  10. added 3 commits that reference this issue on Aug 6, 2020
    54d6e63
    3b80b3b
    081b3e1
  11. jklymak commented on Aug 14, 2020

    @jklymak
    Member

    From the above, I take it that this has been done using other PRs. Please feel free to re-open if I've misread.

  12. QuLogic commented on Aug 14, 2020

    @QuLogic
    Member

    @tacaswell's PR is still in Draft.

  13. added 2 commits that reference this issue on Sep 16, 2020
    e95a990
    6a1a6e9
  14. modified the milestones: , v3.4.0 on Sep 24, 2020
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