Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python和matplotlib制作4d绘图_Python_Plot_Matplotlib - Fatal编程技术网

如何使用Python和matplotlib制作4d绘图

如何使用Python和matplotlib制作4d绘图,python,plot,matplotlib,Python,Plot,Matplotlib,我正在寻找一种使用Python和matplotlib创建四维绘图(曲面加色标)的方法。我能够使用前三个变量生成曲面,但是我没有成功地为第四个变量添加颜色比例。下面是我的数据的一小部分。任何帮助都将不胜感激。谢谢 数据子集 var1 var2 var3 var4 10.39 73.32 2.02 28.26 11.13 68.71 1.86 27.83 12.71 74.27 1.89 28.26 11.46 91.06 1.63

我正在寻找一种使用Python和matplotlib创建四维绘图(曲面加色标)的方法。我能够使用前三个变量生成曲面,但是我没有成功地为第四个变量添加颜色比例。下面是我的数据的一小部分。任何帮助都将不胜感激。谢谢

数据子集

var1    var2    var3    var4
10.39   73.32   2.02    28.26
11.13   68.71   1.86    27.83
12.71   74.27   1.89    28.26
11.46   91.06   1.63    28.26
11.72   85.38   1.51    28.26
13.39   78.68   1.89    28.26
13.02   68.02   2.01    28.26
12.08   64.37   2.18    28.26
11.58   60.71   2.28    28.26
8.94    65.67   1.92    27.04
11.61   59.57   2.32    27.52
19.06   74.49   1.69    63.35
17.52   73.62   1.73    63.51
19.52   71.52   1.79    63.51
18.76   67.55   1.86    63.51
19.84   53.34   2.3     63.51
20.19   59.82   1.97    63.51
17.43   57.89   2.05    63.38
17.9    59.95   1.89    63.51
18.97   57.84   2       63.51
19.22   57.74   2.05    63.51
17.55   55.66   1.99    63.51
19.22   101.31  6.76    94.29
19.41   99.47   6.07    94.15
18.99   94.01   7.32    94.08
19.88   103.57  6.98    94.58
19.08   95.38   5.66    94.14
20.36   100.43  6.13    94.47
20.13   98.78   7.37    94.47
20.36   89.36   8.79    94.71
20.96   84.48   8.33    94.01
21.02   83.97   6.78    94.72
19.6    95.64   6.56    94.57

要创建所需的绘图,我们需要使用matplotlib的
plot\u曲面
来绘制
Z
vs
(X,Y)
曲面,然后使用关键字参数
facecolors
为每个面片传递新颜色

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

# create some fake data
x = y = np.arange(-4.0, 4.0, 0.02)
# here are the x,y and respective z values
X, Y = np.meshgrid(x, y)
Z = np.sinc(np.sqrt(X*X+Y*Y))
# this is the value to use for the color
V = np.sin(Y)

# create the figure, add a 3d axis, set the viewing angle
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(45,60)

# here we create the surface plot, but pass V through a colormap
# to create a different color for each patch
ax.plot_surface(X, Y, Z, facecolors=cm.Oranges(V))

抱歉,数据格式不正确。它应该是:var1 10.39 11.13 12.71 11.46 11.72 13.39 13.02 12.08 11.58 8.94 11.61 19.06 17.52 19.52 18.76 19.84 20.19 17.43 17.9 18.97 19.22 17.55 19.22 19.41 18.99 19.88 19.08 20.36 20.13 20.36 20.96 21.02 19.6 var2 73.32 68.71 74.27 91.85.38 78.68.68.02 64.37 60.71 65.67 59.57.73.62.53.59.59.89.57.8955.66 101.31 99.47 94.01 103.57 95.38 100.43 98.78 89.36 84.48 83.97 95.64var3 2.02 1.86 1.89 1.63 1.51 1.89 2.01 2.18 2.28 1.92 2.32 1.69 1.73 1.79 1.86 2.3 1.97 2.05 1.99 6.76 6.07 7.32 6.98 5.66 6.13 7 7.37 8.79 8.33 6.78 6.56Chris,你能编辑你的帖子而不是添加评论吗?要使数据如您所期望的那样显示出来,请使用代码格式(高亮显示它并按下看起来像花括号的按钮)。此外,张贴您目前拥有的代码。如果这样做,您更有可能获得良好的响应。如何使用
mpl\u工具包中的
Axes3D
。mplot3d