Thanks to @BERA's comment, I found Matplotlib, a very powerful plotting tool that comes with standard python distributions, so it is also available in QGIS.
Here's an example for a console script that plots a polyline's Z values (M values would work similar, btw):
import matplotlib.pyplot as plt
import numpy as np
from qgis._core import QgsVertexId
layer = iface.activeLayer()
lines = layer.selectedFeatures()
lineGeometries = [line.geometry().constGet() for line in lines]
distances = []
zValues = []
# get x and y values
for geo in lineGeometries:
for i in range(0, geo.vertexCount() - 1):
distances.append(geo.segmentLength(QgsVertexId(_vertex=i-1)))
zValues.append(geo[i].z())
distances = np.cumsum(distances)
# Plot
plt.plot(distances, zValues, 'g')
plt.xlabel("Distance")
plt.ylabel("Z Value")
plt.title("Z Value Plot")
plt.show()
The function chooses the selected polyline(s) of the active layer. The resulting plot can be zoomed, stretched and panned by the control buttons of the plot window:

(The control buttons don't fit well well with QGIS dark theme, but that's a minor issue I'd say)
More customisation is possible, the matplotlib
module offers huge possibilities I still need to explore.