在 x 轴上绘制元组列表 [英] Plot a list of tuples on x axis
本文介绍了在 x 轴上绘制元组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下数据
x = [(1,0), (0, 1), (2, 1), (3, 1)]
y = [1, 4, 8.5, 17.5]
我想按以下方式绘制
但 matplotlib 将 x 视为 2 列向量,因此 y
数据被绘制两次.有关如何以上述格式生成图的建议将非常有帮助.
But matplotlib considers x as a 2 column vector so the y
data is plotted twice.
Suggestions on how to generate a plot in the above-mentioned format will be really helpful.
推荐答案
您还可以将元组转换为字符串并绘制分类散点图:
You can also convert the tuples to strings and plot a categorical scatter:
plt.scatter([str(i) for i in x], y)
这篇关于在 x 轴上绘制元组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文