Python matplotlib 3d--插入数据

Python matplotlib 3d--插入数据,python,matplotlib,graph,3d,Python,Matplotlib,Graph,3d,我是编程的初学者。我大约2个月前开始工作,所以请耐心等待我:-) 所以我想在Python3.4上用matplotlib制作一个3d曲面图 我看了很多关于这方面的教程,但我没有找到与我需要做的完全一样的东西。我希望你能帮助我。 在所有的视频中,他们给了meshgrid一个3轴(x,y,z)之间的关系,但我不想这样。我想做的是: 我有16个传感器,它们放在4行上,每行有4个传感器,因此第一行是1,2,3,4,第二行是5,6,7,8,依此类推(传感器的顺序非常重要)。例如,传感器编号4=200,从0到

我是编程的初学者。我大约2个月前开始工作,所以请耐心等待我:-) 所以我想在Python3.4上用matplotlib制作一个3d曲面图

我看了很多关于这方面的教程,但我没有找到与我需要做的完全一样的东西。我希望你能帮助我。 在所有的视频中,他们给了meshgrid一个3轴(x,y,z)之间的关系,但我不想这样。我想做的是: 我有16个传感器,它们放在4行上,每行有4个传感器,因此第一行是1,2,3,4,第二行是5,6,7,8,依此类推(传感器的顺序非常重要)。例如,传感器编号4=200,从0到800。我想用x和y轴仅用于图中的正确位置。例如,传感器4(=200从800)被放置在第四列的第一行…因此..x=4,y=1,z=200从800开始,就像以前一样。因此,最后每个传感器只有一个“真实”值..z


如何使用matplotlib为所有16个传感器导入此类数据以制作3d绘图?我非常感谢任何帮助。

您需要从某个地方开始。假设数据是16个值的列表。然后您可以创建一个2D数组,并将该数组显示为图像

import numpy as np
import matplotlib.pyplot as plt

# input data is a list of 16 values, 
# the first value is of sensor 1, the last of sensor 16
input_data = [200,266,350,480,
              247,270,320,511,
              299,317,410,500,
              360,360,504,632]
# create numpy array from list and reshape it to a 4x4 matrix
z = np.array(input_data).reshape(4,4)
# at this point you can already show an image of the data
plt.imshow(z)
plt.colorbar()

plt.show()

现在,在3D打印中以高度而不是2D打印中以颜色打印值的选项是使用
bar3d
打印

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

# input data is a list of 16 values, 
# the first value is of sensor 1, the last of sensor 16
input_data = [200,266,350,480,
              247,270,320,511,
              299,317,410,500,
              360,360,504,632]

# create a coordinate grid
x,y = np.meshgrid(range(4), range(4))

ax = plt.gcf().add_subplot(111, projection="3d")
#plot the values as 3D bar graph
# bar3d(x,y,z, dx,dy,dz) 
ax.bar3d(x.flatten(),y.flatten(),np.zeros(len(input_data)), 
         np.ones(len(input_data)),np.ones(len(input_data)),input_data)

plt.show()

也可以打印曲面打印,但在这种情况下,栅格将定义曲面平铺的边

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

# input data is a list of 16 values, 
# the first value is of sensor 1, the last of sensor 16
input_data = [200,266,350,480,
              247,270,320,511,
              299,317,410,500,
              360,360,504,632]

# create a coordinate grid
x,y = np.meshgrid(range(4), range(4))
z = np.array(input_data).reshape(4,4)

ax = plt.gcf().add_subplot(111, projection="3d")
#plot the values as 3D surface plot 
ax.plot_surface(x,y,z)

plt.show()

您需要从某个地方开始。假设数据是一个包含16个值的列表。然后您可以创建一个二维数组,并将该数组显示为图像

import numpy as np
import matplotlib.pyplot as plt

# input data is a list of 16 values, 
# the first value is of sensor 1, the last of sensor 16
input_data = [200,266,350,480,
              247,270,320,511,
              299,317,410,500,
              360,360,504,632]
# create numpy array from list and reshape it to a 4x4 matrix
z = np.array(input_data).reshape(4,4)
# at this point you can already show an image of the data
plt.imshow(z)
plt.colorbar()

plt.show()

现在,在3D打印中以高度而不是2D打印中以颜色打印值的选项是使用
bar3d
打印

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

# input data is a list of 16 values, 
# the first value is of sensor 1, the last of sensor 16
input_data = [200,266,350,480,
              247,270,320,511,
              299,317,410,500,
              360,360,504,632]

# create a coordinate grid
x,y = np.meshgrid(range(4), range(4))

ax = plt.gcf().add_subplot(111, projection="3d")
#plot the values as 3D bar graph
# bar3d(x,y,z, dx,dy,dz) 
ax.bar3d(x.flatten(),y.flatten(),np.zeros(len(input_data)), 
         np.ones(len(input_data)),np.ones(len(input_data)),input_data)

plt.show()

也可以打印曲面打印,但在这种情况下,栅格将定义曲面平铺的边

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

# input data is a list of 16 values, 
# the first value is of sensor 1, the last of sensor 16
input_data = [200,266,350,480,
              247,270,320,511,
              299,317,410,500,
              360,360,504,632]

# create a coordinate grid
x,y = np.meshgrid(range(4), range(4))
z = np.array(input_data).reshape(4,4)

ax = plt.gcf().add_subplot(111, projection="3d")
#plot the values as 3D surface plot 
ax.plot_surface(x,y,z)

plt.show()

你能澄清一下你的解释吗?我不明白。这句话的意思是什么:
传感器编号4=200从一个skala从0到800
你首先要了解你有什么样的数据,你有三个1D数组,三个元素的元组,…?我的意思是z可以取0到800的值,在这个例子中是400。I希望现在我上传了Piscure,你能理解我的意思!!谢谢你的评论。你试图澄清你的解释吗?我不明白。这句话是什么意思:
传感器编号4=200从0到800从skala到
你首先要了解你有什么样的数据,你有三个1D数组,三个元组吗元素,…?我的意思是z可以取0到800的值,在这个例子中是400。我希望现在我上传了Piscure,你能理解我的意思!!谢谢你的评论非常感谢!!这帮了我很多忙..真的!!但不是使用bar3d plot..也可以用这些数据制作3d曲面图吗..谢谢,但是它不是真正可读的,看这个图,谁会猜到它绘制了16个不同的传感器数据?当然这是你的选择。非常感谢!!这对我帮助很大..真的!!但不是使用bar3d plot..也可以用这些数据绘制3d曲面图吗?谢谢,但它不是真正可读的,看这个图,who你猜这会绘制16个不同的传感器数据吗?当然这是你的选择。