0

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
asked Oct 18, 2022 at 12:48
3
  • The code here may help. gis.stackexchange.com/questions/277317/… Commented Oct 18, 2022 at 13:18
  • Are you sure you didn't forget the plt.show() command at the end? Commented Oct 18, 2022 at 14:38
  • No it just gives three dimension axis with no lidar data Commented Oct 18, 2022 at 14:56

2 Answers 2

0

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.

enter image description here

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
0
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()

enter image description here

answered May 22 at 18:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.