pandas 中带有数据点的线图 [英] Line plot with data points in pandas
问题描述
使用pandas
我可以轻松地绘制线条图:
Using pandas
I can easily make a line plot:
import pandas as pd
import numpy as np
%matplotlib inline # to use it in jupyter notebooks
df = pd.DataFrame(np.random.randn(50, 4),
index=pd.date_range('1/1/2000', periods=50), columns=list('ABCD'))
df = df.cumsum()
df.plot();
但是我无法弄清楚如何将数据绘制为直线上的点,如本例所示:
But I can't figure out how to also plot the data as points over the lines, as in this example:
这个matplotlib示例似乎可以提供建议,但我找不到方法使用熊猫绘图功能来做到这一点.而且我对学习如何使用熊猫特别感兴趣,因为我一直在使用数据框.
This matplotlib example seems to suggest the direction, but I can't find how to do it using pandas plotting capabilities. And I am specially interested in learning how to do it with pandas because I am always working with dataframes.
有任何线索吗?
推荐答案
您可以对文档:
style:列表或字典
style : list or dict
matplotlib线条样式
matplotlib line style per column
因此,您可以为所有行设置一种线型,或者为每行设置不同的线型.
So, you could either just set one linestyle for all the lines, or a different one for each line.
例如这样做与您要求的类似:
e.g. this does something similar to what you asked for:
df.plot(style='.-')
要为每行定义不同的标记和线型,可以使用列表:
To define a different marker and linestyle for each line, you can use a list:
df.plot(style=['+-','o-','.--','s:'])
您还可以将 markevery
传递给matplotlib
的plot命令,仅以给定间隔绘制标记
You can also pass the markevery
kwarg onto matplotlib
's plot command, to only draw markers at a given interval
df.plot(style='.-', markevery=5)
这篇关于 pandas 中带有数据点的线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!