how to do it?

This is the full script that the test.las file to visualize it with mathplotlib.

import numpy as np
import laspy
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

input_las = laspy.file.File("test.las", mode="r")
point_records = input_las.points.copy()

lasScaleX = input_las.header.scale[0]
lasOffsetX = input_las.header.offset[0]
lasScaleY = input_las.header.scale[1]
lasOffsetY = input_las.header.offset[1]
lasScaleZ = input_las.header.scale[2]
lasOffsetZ = input_las.header.offset[2]

p_X = np.array((point_records['point']['X'] * lasScaleX) + lasOffsetX)
p_Y = np.array((point_records['point']['Y'] * lasScaleY) + lasOffsetY)
p_Z = np.array((point_records['point']['Z'] * lasScaleZ) + lasOffsetZ)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(p_X, p_Y, p_Z, c='r', marker='o')
plt.show()

LAS and laspy specfic code

input_las = laspy.file.File("test.las", mode="r")
point_records = input_las.points.copy()

The first function opens the test.las file in read only mode. With the second function all points with there attributes are conveniently copied to an array. This way we can access all X,Y and Z values at once.

lasScaleX = input_las.header.scale[0]
lasOffsetX = input_las.header.offset[0]
lasScaleY = input_las.header.scale[1]
lasOffsetY = input_las.header.offset[1]
lasScaleZ = input_las.header.scale[2]
lasOffsetZ = input_las.header.offset[2]

All coordinates and heights are scaled to integers within the LAS/LAZ format. So we need to rescale them again. Therefore the scaling and offset parameters have to be read from the header.

p_X = np.array((point_records['point']['X'] * lasScaleX) + lasOffsetX)
p_Y = np.array((point_records['point']['Y'] * lasScaleY) + lasOffsetY)
p_Z = np.array((point_records['point']['Z'] * lasScaleZ) + lasOffsetZ)

This code actually does the rescaling and stores the coordinates for X, Y and heights Z to seperate numpy arrays.

More information about laspy can be found here Additional Infromation about the LAS/LAZ format is available here or here

plotting the pointcloud

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(p_X, p_Y, p_Z, c='r', marker='o')
plt.show()

So finally we are able to setup our plot and use the scatter plot to visualize the points as red circles.