简体   繁体   中英

Shading time series data from pandas dataframe

I have two Pandas dataframes: svt_data and 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() . 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. 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.
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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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