Matplotlib用线连接散点图-Python [英] Matplotlib connect scatterplot points with line - Python
本文介绍了Matplotlib用线连接散点图-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个列表,日期和值.我想使用matplotlib绘制它们.以下创建了我的数据的散点图.
I have two lists, dates and values. I want to plot them using matplotlib. The following creates a scatter plot of my data.
import matplotlib.pyplot as plt
plt.scatter(dates,values)
plt.show()
plt.plot(dates, values)
创建折线图.
但是我真正想要的是一个散点图,其中的点由一条线连接.
But what I really want is a scatterplot where the points are connected by a line.
类似于R:
plot(dates, values)
lines(dates, value, type="l")
,这为我提供了一个散点图,这些散点图用连接这些点的线覆盖.
, which gives me a scatterplot of points overlaid with a line connecting the points.
我如何在python中做到这一点?
How do I do this in python?
推荐答案
我认为@Evert有正确的答案:
I think @Evert has the right answer:
plt.scatter(dates,values)
plt.plot(dates, values)
plt.show()
与
plt.plot(dates, values, '-o')
plt.show()
或您喜欢的任何 linestyle .
这篇关于Matplotlib用线连接散点图-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文