过去几天我一直在网上搜索,没有看到任何解决方案。如果有人能看一下,我将不胜感激。
我试图绘制一个4D图,以显示在给定的经度、纬度和高度处的风向变化。
当物体从一个高度移动到另一个高度时,我在图表中看到了一个跳跃。可以用线把这些点连接起来吗?以指示这是运动。
示例代码如下所示:
import numpy as np
from matplotlib import pyplot as plt
lon = np.array([278.6695, 278.67,278.672265 ])
lat = np.array([48.476151, 48.472578621119, 48.45994295 ])
Z = np.array([20000, 26502.51477,26501.65171])
distance = np.array([72.63856248, 70, 60 ])
fig = plt.figure(6)
ax = fig.add_subplot(111, projection='3d')
img = ax.scatter(lon, lat, Z, c=distance, cmap='inferno', alpha=1)
fig.colorbar(img)
ax.set_xlabel('longitude [Deg]')
ax.set_ylabel('latitude [Deg]')
ax.set_zlabel('Altitude [Km]')
plt.show()
绘制整个数据
的结果
其次,我想用一种颜色来显示距离(即黑色)而不是使用多种颜色。我的最终目标是有一个这样的情节
1条答案
按热度按时间vuktfyat1#
此答案显示如何创建您所要求的最终打印。这两种请求(单色和连接线)都是非常可能的。谷歌搜索你想要的情节图像显示,它最初是一个
animation
,这是我已经包括的其他东西。回答
使用
ax.plot(...)
而不是ax.scatter(...)
,以便用直线连接这些点。然后,您可以添加一些其他功能,使输出看起来更像您的最终目标。输出示例
这是一个数字显示了你的最终目标。下面添加了用于再现该图的代码。
还可以创建随时间推移的情节动画。注意,线的颜色随着距起始位置的距离增加而改变。此功能很容易被禁用。
代码
这是一些用于静态和动画图形的设置代码。
这是图的静态版本。
这是一段时间内创建情节动画版本的代码。
编辑
为了修复代码的动画部分与Matplotlib 3.5.1兼容,必须更改
animate(...)
函数中的以下代码部分。替换以下内容:有:
这只是将
set_3d_properties(...)
的输入更改为列表格式,这是Matplotlib 3.5.1中的新标准。有关问题的描述,请参阅此open issue。这样有用吗