You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Patch3DCollection doesn't update color after calling set_color #3370
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.
frommpl_toolkits.mplot3dimportAxes3Dimportmatplotlib.animationasanimationimportmatplotlib.pylabaspltimportnumpyasnpNUM_POINTS=10values= []
foriiinxrange(NUM_POINTS):
values.append(np.random.random_integers(0, 500, 3))
points= []
n=0deftwo_dim_example():
defanimate(i):
""" Goal is to slowly add new points and have the most current point in red while all other points are gray """globaln# No more animation neededifn>=NUM_POINTS:
return# Change color of all old pointsforpointinpoints:
point.set_color('gray')
x, y, z=values[n]
point=ax2D.scatter(x, y, s=75, c='red', marker='o')
points.append(point)
n+=1ax2D=fig1.add_subplot(111)
ani=animation.FuncAnimation(fig1, animate, interval=500)
plt.show()
defthree_dim_example():
defanimate(i):
""" Goal is to slowly add new points and have the most current point in red while all other points are gray """globaln# No more animation neededifn>=NUM_POINTS:
return# Change color of all old pointsforpointinpoints:
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+=1ax3D=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()
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.
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).
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 notifications@github.com
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 notifications@github.com
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