Skip to content

Patch3DCollection doesn't update color after calling set_color #3370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
durden opened this issue Aug 15, 2014 · 8 comments · Fixed by #18189
Closed

Patch3DCollection doesn't update color after calling set_color #3370

durden opened this issue Aug 15, 2014 · 8 comments · Fixed by #18189
Assignees
Milestone

Comments

@durden
Copy link

durden commented Aug 15, 2014

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()
@tacaswell
Copy link
Member

@tacaswell tacaswell added this to the v1.4.x milestone Aug 17, 2014
@tacaswell tacaswell modified the milestones: unassigned, v1.4.x Feb 7, 2015
@tacaswell
Copy link
Member

attn @WeatherGod

@WeatherGod
Copy link
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 notifications@github.com
wrote:

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


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

@WeatherGod
Copy link
Member

PR #4090 fixes this completely.

On Mon, Feb 9, 2015 at 3:47 PM, Thomas A Caswell notifications@github.com
wrote:

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


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

@WeatherGod
Copy link
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).

@durden
Copy link
Author

durden commented Dec 9, 2015

@WeatherGod No problem. Thanks for the update!

tacaswell pushed a commit to tacaswell/matplotlib that referenced this issue Aug 6, 2020
closes matplotlib#3370

We need to do an extra step to propagate the color information back to
the 3D projections
tacaswell pushed a commit to tacaswell/matplotlib that referenced this issue Aug 6, 2020
closes matplotlib#3370

We need to do an extra step to propagate the color information back to
the 3D projections
tacaswell pushed a commit to tacaswell/matplotlib that referenced this issue Aug 10, 2020
closes matplotlib#3370

We need to do an extra step to propagate the color information back to
the 3D projections
@jklymak
Copy link
Member

jklymak commented Aug 14, 2020

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

@QuLogic
Copy link
Member

QuLogic commented Aug 14, 2020

@tacaswell's PR is still in Draft.

@QuLogic QuLogic reopened this Aug 14, 2020
QuLogic pushed a commit to tacaswell/matplotlib that referenced this issue Sep 16, 2020
closes matplotlib#3370

We need to do an extra step to propagate the color information back to
the 3D projections
QuLogic pushed a commit to tacaswell/matplotlib that referenced this issue Sep 17, 2020
closes matplotlib#3370

We need to do an extra step to propagate the color information back to
the 3D projections
@QuLogic QuLogic removed this from the unassigned milestone Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment