简体   繁体   English

matplotlib“旋转”渐变

[英]matplotlib “rotate” gradient

I have this code that display a triangle filled with a gradient. 我有这段代码显示填充有渐变的三角形。

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')

X, Y = np.meshgrid(np.linspace(0,1), np.linspace(0,1)) 
Z = 1.-X-Y
Z[Z<0] = 0

cset = ax.contourf(X, Y, Z, zdir='x', levels=np.linspace(0,1),offset=0, cmap=plt.cm.jet)
ax.set_xlabel('X')
ax.set_xlim(0, 1)
ax.set_ylabel('Y')
ax.set_ylim(0,1)
ax.set_zlabel('Z')
ax.set_zlim(0,1)    
plt.show()

How can I have the gradient "slices" in the other "direction"? 如何在另一个“方向”上设置渐变“切片”? I mean, the gradient should look like this: 我的意思是,渐变应如下所示:

The answer to this question has already been given here: 这个问题的答案已经在这里给出:

Fill a triangle in 3D matplolib plot with a color gradient 用颜色渐变填充3D Matplolib图中的三角形

where I show two ways of producing a gradient fill in a 3D triangle using contourf and plot_surface . 在这里,我展示了两种使用contourfplot_surface在3D三角形中生成渐变填充的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM