简体   繁体   English

来自Pandas数据框的阴影时间序列数据

[英]Shading time series data from pandas dataframe

I have two Pandas dataframes: svt_data and asp_data. 我有两个熊猫数据帧:svt_data和asp_data。 The first is time series data and the second is specific times in that series. 第一个是时间序列数据,第二个是该序列中的特定时间。 I can plot the time series data no problem using svt_data.plot() . 我可以使用svt_data.plot()绘制时间序列数据。 I want to then shade the specific times from the second data frame. 然后,我想从第二个数据帧中阴影特定时间。

In the past I have done this, not using pandas dataframes but rather native python lists, by iterating over the elements of the list and using matplotlib's plt.axvline function. 过去,我通过遍历列表元素并使用matplotlib的plt.axvline函数来执行此操作,而不是使用pandas数据框,而是使用本机python列表。 However, when I iterate over the dataframe elements and use this function, it produces two figures instead of one. 但是,当我遍历数据框元素并使用此函数时,它将生成两个数字而不是一个数字。 It shades the specific times from the second dataframe on one graph and gives me the time series on another graph. 它在一个图表上的第二个数据帧处遮盖了特定时间,并在另一个图表上给了我时间序列。

How can I get them on the same plot? 我怎样才能让他们在同一地块上?

    from numpy import *
    from pandas import *
    import pylab as plt

    svt_data = read_csv("D:\\Archives\\workspace\\sizeTimeData.txt", sep=" ", header=None, names=["time", "size"])
    asp_data = read_csv("D:\\Archives\\workspace\\asperityFailTimes.txt", sep=" ", header=None, names=["asp1"])

    for i in asp_data.asp1:
        plt.axvline(i,color=(0,1,0),alpha='0.5')

    svt_data.plot(x='time', y="size", color="black")
    plt.show()

Edit: Here is what a similar graph looks like having produced it using lists instead of dataframes. 编辑:这是使用列表而不是数据框生成类似图形的样子。

IMG

I've switched to pandas because my data sets are getting larger and larger and it is taking unreasonable amounts of time to plot things and even to read in the data. 我之所以选择熊猫,是因为我的数据集越来越大,并且绘制事物甚至读取数据花费了不合理的时间。

Zoomed in on one cluster 放大一个集群

I think that pandas.DataFrame.plot creates a new figure by default. 我认为pandas.DataFrame.plot默认情况下会创建一个新图。
If you just switch the plotting command, plotting the data from the dataframe before and the lines after , you will get a single figure. 如果你只是切换绘图命令,绘制之前从数据帧的数据和线,你会得到一个单一的数字。

svt_data.plot(x='time', y="size", color="black")

for i in asp_data.asp1:
    plt.axvline(i,color=(0,1,0),alpha='0.5')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM