Repository navigation
Description
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
tacaswell commentedon Aug 15, 2014
I think that this SO question is related: http://stackoverflow.com/questions/8971309/matplotlib-3d-scatter-color-lost-after-redraw/8974087#8974087
tacaswell commentedon Feb 7, 2015
attn @WeatherGod
WeatherGod commentedon Feb 7, 2015
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:
Add get/set color methods for some 3d collections
WeatherGod commentedon Feb 9, 2015
PR #4090 fixes this completely.
On Mon, Feb 9, 2015 at 3:47 PM, Thomas A Caswell [email protected]
wrote:
Add get/set color methods for some 3d collections
WeatherGod commentedon Dec 1, 2015
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 commentedon Dec 9, 2015
@WeatherGod No problem. Thanks for the update!
FIX: Add get/set color methods for some 3d collections
FIX: Add get/set color methods for some 3d collections
FIX: Add get/set color methods for some 3d collections
jklymak commentedon 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 commentedon Aug 14, 2020
@tacaswell's PR is still in Draft.
FIX: Add get/set color methods for some 3d collections
FIX: Add get/set color methods for some 3d collections