0

Is it possible to plot time series data within a fixed time period?

Assume I have the following sample dataset:

import pandas as pd
date_rng = pd.date_range(start="1.1.2023", end="10.1.2023", freq="15T")
df = pd.DataFrame(date_rng, columns=["datetime"])
df["value"] = pd.Series(range(len(date_rng)))

How to plot this data for a fixed period (e.g. from 6:00 to 6:00 the next day, or for every 8 hours) using seaborn? This should result in a plot with one line (for the mean curve) and an error band, similar to the example shown here.

normanius
  • 8,629
  • 7
  • 53
  • 83

1 Answers1

0

Works well with strftime:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
date_rng = pd.date_range(start="1.1.2023", end="10.1.2023", freq="15T")
df = pd.DataFrame(date_rng, columns=["datetime"])
df["value"] = pd.Series(range(len(date_rng)))
df["time"] = df['datetime'].dt.strftime('%H:%M:%S')
df["value"] = pd.Series(range(len(date_rng)))
sns.lineplot(x="time", y="value", data=df)
plt.show()
Bibhav
  • 1,579
  • 1
  • 5
  • 18