首页 > 解决方案 > 我想知道如何使用带有 XYZ 值的 python matplotlib 进行绘制

问题描述

我有一个 XYZ 测量

我尝试了 mplot3d 示例代码,但我不知道。

我想绘制一个图表,显示这些值的高度差异。

我想知道如何将值应用于示例。

有下面的图片

图片

            x y z
        ```
          X              Y             Z
        0.0056      -149.00237      0.01375
        -11.99014       -148.5314       0.01323
        -23.90088       -147.08148      0.01294
        -35.67262       -144.68161      0.01386
        -47.19637       -141.34179      0.0139
        -58.41713       -137.08002      0.01303
        -69.24989       -131.93131      0.01319
        -79.64266       -125.94063      0.01233
        -89.52245       -119.11801      0.0124
        -98.81825       -111.51743      0.01235
        ..........
        ```

示例代码

```    
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import

import matplotlib.pyplot as plt
import numpy as np


n_radii = 8
n_angles = 36

# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
radii = np.linspace(0.125, 1.0, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)[..., np.newaxis]

# Convert polar (radii, angles) coords to cartesian (x, y) coords.
# (0, 0) is manually added at this stage,  so there will be no duplicate
# points in the (x, y) plane.
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())

# Compute z to make the pringle surface.
z = np.sin(-x*y)

fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)

plt.show()

```

标签: pythonmatplotlib

解决方案


推荐阅读