In [1]:
#!pip install seaborn
In [2]:
# Time Series Plot
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = {
''''date'''': pd.date_range(start=''''2023-01-01'''', periods=100, freq=''''D''''),
''''value'''': np.random.randn(100).cumsum()
}
df = pd.DataFrame(data)
sns.lineplot(x=''''date'''', y=''''value'''', data=df)
plt.xlabel(''''Date'''')
plt.ylabel(''''Value'''')
plt.title(''''Time Series Plot'''')
plt.show()
In [3]:
# Customizing the Time Series Plot
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = {
''''date'''': pd.date_range(start=''''2023-01-01'''', periods=100, freq=''''D''''),
''''value'''': np.random.randn(100).cumsum()
}
df = pd.DataFrame(data)
sns.lineplot(x=''''date'''', y=''''value'''', data=df, linestyle=''''--'''', marker=''''o'''', color=''''blue'''')
plt.xlabel(''''Date'''')
plt.ylabel(''''Value'''')
plt.title(''''Customized Time Series Plot'''')
plt.show()
In [5]:
# Plotting Multiple Time Series
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = {
''''date'''': pd.date_range(start=''''2023-01-01'''', periods=100, freq=''''D''''),
''''value1'''': np.random.randn(100).cumsum(),
''''value2'''': np.random.randn(100).cumsum(),
''''value3'''': np.random.randn(100).cumsum(),
}
df = pd.DataFrame(data).melt(''''date'''', var_name=''''series'''', value_name=''''value'''')
sns.lineplot(x=''''date'''', y=''''value'''', hue=''''series'''', data=df)
plt.xlabel(''''Date'''')
plt.ylabel(''''Value'''')
plt.title(''''Multiple Time Series Plot'''')
plt.show()