茎状图示

茎图的绘制是从基线到y坐标的垂直线绘制cosine(x) w.r.t x,使用 ‘-.’ 作为绘制垂直线的图案。

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. # returns 10 evenly spaced samples from 0.1 to 2*PI
  4. x = np.linspace(0.1, 2 * np.pi, 10)
  5. markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')
  6. # setting property of baseline with color red and linewidth 2
  7. plt.setp(baseline, color='r', linewidth=2)
  8. plt.show()

茎状图示图例3

此示例使用了: * matplotlib.axes.Axes.stem()

下载这个示例