# Python: How to plot time interval from a Dataframe in Pandas

I have the a dataframe(df) which has the data of a Job being executed at different time intervals. It includes the following details about the execution of a job:

1. Job Start Time (START)
2. Job End Time (END)
3. Time Interval (interval) i.e., END - START.

A small part of dataframe is shown below.

Dataframe(df):

  END    |  START   |  interval
1423.0   |  1357.0  |    66.0
33277.0  |  33325.0 |   -48.0
42284.0  |  42250.0 |    34.0
53466.0  |  53218.0 |   248.0
62158.0  |  62073.0 |    85.0


I want to plot a graph with the x-axis as the timestamp and the y-axis with the interval. I tried to do it with the START time but it is not giving the correct result. How can we do this?

Code

fig_dims = (12, 10)
fig, ax = plt.subplots(figsize=fig_dims)

sns.lineplot(x = 'START', y = 'interval', data = df, ax = ax)


Required Output
x-axis - Timestamp
y-axis - Interval

• What timestamp would a start value of 1357 be? Feb 24, 2021 at 12:58
• It will be 1357 Feb 24, 2021 at 12:59
• Then I am not exactly sure why the current plot is not what you want? The x-axis shows the values from 0 up to 1*10^9, which is the range of the START column, and the y-axis shows the interval, which can have both positive and negative values. Feb 24, 2021 at 13:13
• Yes, I get it but this graph is not making any sense, is there a different way to plot this so that I can infer something? Feb 24, 2021 at 13:19
• That completely depends on what you are trying to infer. Because you have such a long range of values that shift up and down quite a bit the line chart get compressed quite heavily using the default size. You could try increasing the size of plot (mainly the width), however you might end up with an extremely large plot before you can actually can see the individual line. Feb 24, 2021 at 13:22

Some suggested alternative plotting methods to visualise this data:

1. Histogram of the y-axis. Check the distribution of time intervals

df.plot.hist(by='interval', bins=10) #test varying the bin size

2. Plot smaller subsets of the data if the order is important e.g. df[:100].plot() furthermore, if there is periodicity in the data, e.g. daily, hourly etc. you could plot each hour on top of each other (in a different colour) to compare the differences between periods.

• Did this solve your problem? Let me know if you have any questions
– WBM
Feb 26, 2021 at 15:33