你需要从某处开始。所以我们假设这些数据是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()
你可以尝试清理你的解释?我没有跟随。线的含义:'从0到800的skala传感器编号4 = 200' –
你首先必须了解你有什么样的数据,你有三个一维数组,三个元素的元组,......? –
我的意思是z可以取值从0到800,在这个例子中它是400. – GeorgM