Matplotlib 3D Plot Colors Appear Darker Than Normal

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 18:33:23

问题


I'm using the mpl_toolkits to plot surfaces in 3d using Axes3D and plot_surface.

I visualize the output in the following way,

You can clearly see that there is a grey tint to the entire surface when the colors are supposed to resemble the colorbar on the right.

I see this behavior in several other plots out there doing similar things. For example here https://stackoverflow.com/a/20475233/2495342

I am using the latest anaconda distribution of python and running my code within spyder which uses the Qt4Agg backend. I get the same behavior under linux and windows. Using a different colormap does not help either. The visualization is always tinted grey.

I haven't found much help through google, so any help is appreciated.

Here is a quick demo

import numpy as np
from matplotlib import pyplot
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D

X, Y = np.meshgrid(np.arange(-1, 1, 0.1), np.arange(-1, 1, 0.1))
Z = np.zeros_like(X)

F = np.sqrt(X**2 + Y**2)
F -= np.min(F)
F /= np.max(F)

fig = pyplot.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=cm.coolwarm(F))

Which returns


回答1:


use shade argument:

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, 
                facecolors=cm.coolwarm(F), shade=False)


来源:https://stackoverflow.com/questions/21768497/matplotlib-3d-plot-colors-appear-darker-than-normal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!