python - Matplotlib如何在两个Y点之间绘制垂直线
问题描述
每个 x 点我有 2 y 点。我可以用这段代码绘制情节:
import matplotlib.pyplot as plt
x = [0, 2, 4, 6]
y = [(1, 5), (1, 3), (2, 4), (2, 7)]
plt.plot(x, [i for (i,j) in y], 'rs', markersize = 4)
plt.plot(x, [j for (i,j) in y], 'bo', markersize = 4)
plt.xlim(xmin=-3, xmax=10)
plt.ylim(ymin=-1, ymax=10)
plt.xlabel('ID')
plt.ylabel('Class')
plt.show()
这是输出:
如何绘制连接每个 y 点对的细线?期望的输出是:
解决方案
推荐阅读
- r - R:仅从街道名称、城市和州获取邮政编码
- django - 我怎样才能找到用户总数?
- c# - 显示二维数组行列计数器
- javascript - 无法解构“未定义”的属性“纬度”
- generics - 使用@CompileStatic 和泛型类时,构造函数不能应用于“(T)”错误
- python - 当 recycleview 中的 viewclass 按钮被按下时如何移动到下一个屏幕,该按钮在 kivy 的屏幕上?
- python - 导入自己的数据,如 MNIST 或 CIFAR10 load_data()
- c++ - 我们可以在不知道其真实类型的情况下将基类指针转换为派生类指针吗?
- asp.net - 将浏览器 PDF 保存到磁盘
- apache-spark - Elasticsearch如何利用集群?