再presenting 4D数据mplot 3D使用的colormaps [英] Representing 4D data in mplot 3D using colormaps

查看:192
本文介绍了再presenting 4D数据mplot 3D使用的colormaps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来改变该颜色表是绑在一个mplot3d表面图的价值?
举个例子,我试图重新present表面温度的对象:

Is there a way to change the value that the colormap is tied to in an mplot3d surface plot?
As an example, I'm trying to represent surface temperature for an object:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

z = np.array([0,1,2,3,4,5,6,7,8,9,10])
radius = np.array([0,1,1.5,1,0,2,4,5,4,2,1])
temp = np.array([150,200,210,220,225,220,195,185,160,150,140])

angle = np.linspace(0,2*np.pi,20)
Z,ANG = np.meshgrid(z,angle)
# transform them to cartesian system
X,Y = radius*np.cos(ANG),radius*np.sin(ANG)

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='jet')
plt.show()

此产生所述物体的三维再presentation,但颜色表是默认捆绑到z轴值。可以在颜色表绑在临时值?

This generates a 3d representation of the object, but the colormap is by default tied to the z-axis value. Can the colormap be tied to the 'temp' value?

(在此例中,温度上映射到Z的相同的方式,该'半径'的值做)

(in this example, 'temp' maps on to Z the same way that the 'radius' values do)

我所知道的一样Mayavi的工具,但如果有可能,我希望在matplotlib的解决方案。

I'm aware of tools like MayaVI, but if it's possible I'm hoping for a solution within matplotlib.

推荐答案

尝试使用 facecolors 在调用 plot_surface

import matplotlib.pyplot as plt
import numpy as np

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

z = np.array([0,1,2,3,4,5,6,7,8,9,10])
radius = np.array([0,1,1.5,1,0,2,4,5,4,2,1])
temp = np.array([150,200,210,220,225,220,195,185,160,150,140])

angle = np.linspace(0,2*np.pi,20)
Z,ANG = np.meshgrid(z,angle)
T,ANG = np.meshgrid(temp,angle)
# transform them to cartesian system
X,Y = radius*np.cos(ANG),radius*np.sin(ANG)

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=cm.jet(T/float(T.max())))
plt.show()

这篇关于再presenting 4D数据mplot 3D使用的colormaps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆