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
Bug summary
The set_color method on the Path3DCollection object, such as the one returned by 3D scatter plot, does not set the color. I am filing this as a new issue because
the MWE here shows the issue is present even before the first display (show call) of the figure
this report describes some other anomalies related to alpha that might favorable to handle together
Code for reproduction
# Can we change color after plotting? NO, independently of the color format.# Note: in 2D set_color() works as expected.importmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dfig=plt.figure()
ax=fig.gca(projection="3d")
sc1=ax.scatter([0,1], [0,1], [1,1], color= (1,0,0,1), depthshade=False)
sc2=ax.scatter([0,1], [0,1], [2,2], color= (1,0,0,1), alpha=0.3, depthshade=True)
sc3=ax.scatter([0,1], [0,1], [3,3], color= (1,0,0,1), alpha=1.0, depthshade=False)
sc4=ax.scatter([0,1], [0,1], [4,4], color= (1,0,0,0.3), alpha=1.0, depthshade=True)
sc1.set_color('blue')
sc2.set_color(['blue', 'blue'])
sc3.set_color([(0,0,1), (0,0,1)])
sc4.set_color([(0,0,1,1), (0,0,1,1)])
sc1.changed() # workaround https://stackoverflow.com/a/8974087 does not work here ax.set_zticks([1,2,3,4])
ax.set_zticklabels(['"blue"', '[b,b]', 'RGB', 'RGBA'])
fig.show()
Actual outcome
While all the scatter plots are expected to have blue color.
Related questions
If the issue is coming from how Axes3D.scatter produces the Path3DCollection, it might be worthy to note the following on the color-related alpha channel.
Context: Does depthshade work with alpha value?
NO, depthshade is negatively overridden if alpha is provided, in addition, channel A from RGBA colors is omitted.
Remark: Since I did not find any note on this alpha vs channel A interaction in the docs, my expectation was to display using the product of alpha and A. Remark holds for 2D as well.
Note: set_alpha() must be called with single scalar, otherwise a TypeError exception is raised.
Note: it seems that both the scatter constructor and set_alpha writes alpha into the color code because of the following
set_alpha(None) does not restore alpha to 1.0, but reverts the negative override on depthscale
set_alpha(1.0) overrides the A channel of RGBA colors
Remark: the above behavior is inconsistent with line plotting for the following reasons:
there, set_alpha(None) reverts only the explicitly provided alpha, not the A channel of RGBA colors
there, set_alpha(1.0) does not overwrite the A channel of RGBA colors, but the minimum of the alpha and A is used, however I would prefer product over minimum.
After some digging, I (re)discovered that the bug is due to the set_facecolor not setting _facecolor3d because it is inherited from the base class (Collection) setting _facecolors. The same for edge colors. I found that PR #5598 (still not applied?) should solve the main issue of set_facecolor and set_edgecolor not working, however those classes may need special attention that use _facecolor2d instead of _facecolors. Workaround till then is to call set_3d_properties(stored_z_coords, 'z') after any set_color.
Bug report
Bug summary
The
set_color
method on thePath3DCollection
object, such as the one returned by 3Dscatter
plot, does not set the color. I am filing this as a new issue becauseshow
call) of the figurealpha
that might favorable to handle togetherCode for reproduction
Actual outcome

While all the scatter plots are expected to have blue color.
Related questions
If the issue is coming from how
Axes3D.scatter
produces thePath3DCollection
, it might be worthy to note the following on the color-related alpha channel.Context: Does depthshade work with alpha value?
Question: Can we change alpha after plotting?
set_alpha()
must be called with single scalar, otherwise aTypeError
exception is raised.set_alpha(None)
does not restore alpha to 1.0, but reverts the negative override on depthscaleset_alpha(1.0)
overrides the A channel of RGBA colorsset_alpha(None)
reverts only the explicitly provided alpha, not the A channel of RGBA colorsset_alpha(1.0)
does not overwrite the A channel of RGBA colors, but the minimum of the alpha and A is used, however I would prefer product over minimum.Matplotlib version
The text was updated successfully, but these errors were encountered: