简体   繁体   English

python 二维轮廓 plot 使用 3d np 数组数据

[英]python 2d contourf plot using 3d np array data

I have a problem here.我这里有问题。

My data is a 3d shape of np array (256, 256, 1) = (x coordinate, y coordinate, pressure value) Now I would like to draw a contour plot using this np array.我的数据是 np 数组 (256, 256, 1) = (x 坐标, y 坐标, 压力值) 的 3d 形状现在我想使用这个 np 数组绘制轮廓 plot。

But the problem is that the shape of my data does not fit into plt.contourf但问题是我的数据形状不适合 plt.contourf

Any idea on how to preprocess my data before feeding it to contourf?关于如何在将数据输入contourf之前对其进行预处理的任何想法?

Since you have a singular value for each position [M,N], you can simply squeeze out that dimension and have it represented by a matrix of shape [M,N].由于每个 position [M,N] 都有一个奇异值,因此您可以简单地挤出该维度并将其表示为形状为 [M,N] 的矩阵。

data = data.squeeze(2)
plt.contourf(data)

The squeezed and original array contain the exact same data, but are just represented slightly differently.压缩数组和原始数组包含完全相同的数据,但表示方式略有不同。

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

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