简体   繁体   English

Matplotlib分离3D数据的2D等高线投影图

[英]Matplotlib separate 2D contour projection plots of 3D data

I am trying to create 2D plots of the projection of 3D data. 我正在尝试创建3D数据投影的2D图。 Very simply, based on this example is there a way to produce the three contour projections shown (in the X, Y, and Z directions) as separate 2D plots? 很简单,基于此示例,是否可以将所示的三个轮廓投影(沿X,Y和Z方向)生成为单独的2D图? I can easily create the contour projection in the Z direction by using the pyplot 'contour' command, but only the '3d' projection 'contour' command seems to be able to take the 'zdir' parameter, and it can't create 2D plots. 我可以使用pyplot'contour'命令轻松地在Z方向上创建轮廓投影,但是只有'3d'投影'contour'命令似乎能够采用'zdir'参数,并且它无法创建2D地块。

The zdir parameter in a 3D contour basically says which axis will be used to determine the contour levels in a 3D plot. 3D轮廓中的zdir参数基本上表示将使用哪个轴确定3D绘图中的轮廓级别。 In a 2D plot this is usually specified by the order of the arguments, so what we normally think of as "Z", that is, the values that determine the contour level, is put in as the third argument. 在2D图中,这通常由参数的顺序指定,因此我们通常认为的“ Z”(即确定轮廓级别的值)作为第三个参数输入。 In the example below, note in particular the first three arguments in each of the contourf calls: 在下面的示例中,尤其要注意每个contourf调用中的前三个参数:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

X, Y, Z = axes3d.get_test_data(0.05)

plt.subplot(131)
cset = plt.contourf(X, Y, Z, cmap=cm.coolwarm)
plt.subplot(132)
cset = plt.contourf(Y, Z, X, cmap=cm.coolwarm)
plt.subplot(133)
cset = plt.contourf(X, Z, Y, cmap=cm.coolwarm)

plt.show()

在此处输入图片说明

Compared to the projections in the 3D plot: 与3D图中的投影相比:

在此处输入图片说明

Note that here I've referred to "the third argument", but there are actually lots of ways that the arguments to contourf can be interpreted, so see the docs for more details, although this approach will generally only work with calls where X, Y, and Z are explicit. 请注意,这里我指的是“第三个参数”,但是实际上有很多方法可以解释contourf的参数,因此请参阅文档以获取更多详细信息,尽管这种方法通常只适用于X, Y和Z是明确的。

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

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