I am trying to plot a las file with one million points in Matplotlib. When I try to plot the file it always gives me a blank result.
This is the code I am using:
import numpy as np
import laspy
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# reading las file and copy points
input_las = laspy.read("C:\\split.las")
point_records = input_las.points.copy()
x_mask_g = np.array(point_records.X)
y_mask_g = np.array(point_records.Y)
z_mask_g = np.array(point_records.Z)
fig_surf_g = plt.figure()
ax = fig_surf_g.add_subplot(111, projection = '3d')
ax.plot_trisurf(x_mask_g, y_mask_g, z_mask_g)
plt.title("Ground Surface")
Vince
20.5k16 gold badges49 silver badges65 bronze badges
2 Answers 2
This works just fine. Obvisouly I use random data, so surface has no real elevation meaning. So, you might check that your input data is correct: data present, no tricky decimal separator, absence of "invalid data", "Not A Number" (NaN) etc.
import matplotlib.pyplot as plt
import numpy as np
# import laspy
import pandas as pd
# reading las file and copy points
# input_las = laspy.read("C:\\split.las")
# point_records = input_las.points.copy()
# create fake data since I do not have your data source at hand
df = pd.DataFrame(columns=["X", "Y", "Z"])
n = 1_000
df.X = np.random.uniform(low=-45, high=45, size=(n,))
df.Y = np.random.uniform(low=-179, high=180, size=(n,))
df.Z = np.random.uniform(low=-1000, high=9000, size=(n,))
x_mask_g = df.X.to_numpy()
y_mask_g = df.Y.to_numpy()
z_mask_g = df.Z.to_numpy()
fig_surf_g = plt.figure()
ax = fig_surf_g.add_subplot(111, projection='3d')
ax.plot_trisurf(x_mask_g, y_mask_g, z_mask_g)
plt.title("Ground Surface")
plt.show()
answered Oct 27, 2022 at 9:12
import pdal
import matplotlib.pyplot as plt
#Read a las file and crop by coordinates: [xmin, xmax], [ymin, ymax]
json = """
[
"E:/data/lidar_1235.laz",
{
"type":"filters.crop",
"bounds":"([385135,385202],[6299297,6299367])"
}
]
"""
pipeline = pdal.Pipeline(json)
count = pipeline.execute()
array = pipeline.arrays[0]
plt.style.use('default')
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(projection='3d')
ax.scatter(array["X"], array["Y"], array["Z"], c=array["Z"], cmap="gist_rainbow",
s=30)
ax.set_xlabel('X coord')
ax.set_ylabel('Y coord')
ax.set_zlabel('Height')
plt.show()
answered May 22 at 18:35
lang-py
plt.show()
command at the end?