除了茎和条形图之外还有另外两个选项是以下使用vlines()
和LineCollection()
选项 1 -- 使用 vlines()
for x, y in enumerate(data):
plt.vlines(x=x, ymin=0, ymax=y, color='r')
或者在一行中不使用循环
plt.vlines(x=range(data.size), ymin=0, ymax=data, color='r')
选项 2 -- 使用 LineCollection()
from matplotlib.collections import LineCollection
lines = [[(x, 0), (x, y)] for x, y in enumerate(data)]
linesCol = LineCollection(lines, linewidths=3, color='r')
fig, ax = plt.subplots()
ax.add_collection(linesCol)
plt.scatter(range(len(data)), data, s=0)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句