Time Series Plots & Graphs
ā¹ļø
Note: The code examples below are for Python and will only display plots if you run them in your own Python environment (e.g., Jupyter Notebook, Google Colab, or a local Python script).
This website shows the code and instructions, but does not render the plots directly.
Explore the most important plots for time series analysis, with code, libraries, and references.
Line Plot
Illustrative Example (SVG)
Story for Kids: Imagine drawing a line that connects the dots for your temperature every day. You can see how it goes up and down!
Simple Tip: Line plots show how things change over time.
A line plot is the most basic way to visualize a time series, showing values over time.
import matplotlib.pyplot as plt
plt.plot(data['date'], data['value'])
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('Line Plot of Time Series')
plt.show()
Required library: matplotlib
Reference: Matplotlib Line Plot
Seasonal Plot
Illustrative Example (SVG)
Story for Kids: If you color each month's temperature with a different color, you can see which months are hottest or coldest every year!
Simple Tip: Seasonal plots show repeating patterns each year or season.
Seasonal plots show how a value changes for each season or period (e.g., each month across years).
import seaborn as sns
import pandas as pd
sns.lineplot(x='month', y='value', hue='year', data=data)
plt.title('Seasonal Plot')
plt.show()
Required libraries: seaborn, pandas, matplotlib
Reference: Forecasting: Principles and Practice
Lag Plot
Illustrative Example (SVG)
Story for Kids: If you plot today's temperature against yesterday's, you can see if warm days follow warm days!
Simple Tip: Lag plots show if today's value depends on yesterday's.
Lag plots help detect autocorrelation by plotting each value against its previous value.
from pandas.plotting import lag_plot
lag_plot(data['value'])
plt.title('Lag Plot')
plt.show()
Required libraries: pandas, matplotlib
Reference: Pandas Lag Plot
Autocorrelation Plot (ACF)
Illustrative Example (SVG)
Story for Kids: It's like checking if your test scores are similar from one week to the next!
Simple Tip: ACF plots show how much the past affects the present.
ACF plots show the correlation of a time series with its own past values at different lags.
from statsmodels.graphics.tsaplots import plot_acf
plot_acf(data['value'])
plt.title('Autocorrelation (ACF) Plot')
plt.show()
Required library: statsmodels, matplotlib
Reference: Statsmodels ACF
Partial Autocorrelation Plot (PACF)
Illustrative Example (SVG)
Story for Kids: If you want to know if your score this week is related to two weeks ago, not just last week, use PACF!
Simple Tip: PACF plots show direct relationships with past values, skipping the middle steps.
PACF plots show the correlation of a time series with its own past values, controlling for shorter lags.
from statsmodels.graphics.tsaplots import plot_pacf
plot_pacf(data['value'])
plt.title('Partial Autocorrelation (PACF) Plot')
plt.show()
Required library: statsmodels, matplotlib
Reference: Statsmodels PACF
Histogram
Illustrative Example (SVG)
Story for Kids: If you count how many days were hot, warm, or cold, you get a histogram!
Simple Tip: Histograms show how often each value happens.
A histogram shows the distribution of values in a time series.
plt.hist(data['value'], bins=20)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Histogram')
plt.show()
Required library: matplotlib
Reference: Matplotlib Histogram
Density Plot
Illustrative Example (SVG)
Story for Kids: It's like a smooth version of a histogram, showing where your data is thickest!
Simple Tip: Density plots show where your data is most crowded.
A density plot is a smoothed version of a histogram, showing the distribution of values.
import seaborn as sns
sns.kdeplot(data['value'])
plt.title('Density Plot')
plt.show()
Required libraries: seaborn, matplotlib
Reference: Seaborn KDE Plot
Boxplot
Illustrative Example (SVG)
Story for Kids: A boxplot is like a treasure chest that shows where most of your data is, and where the surprises are!
Simple Tip: Boxplots show the middle, spread, and outliers in your data.
A boxplot summarizes the distribution, median, quartiles, and outliers of a time series.
plt.boxplot(data['value'])
plt.title('Boxplot')
plt.show()
Required library: matplotlib
Reference: Matplotlib Boxplot
Heatmap
Illustrative Example (SVG)
Story for Kids: A heatmap is like a colorful calendar that shows when things are hot or cold!
Simple Tip: Heatmaps use color to show patterns over time.
A heatmap visualizes values in a matrix, often used for showing seasonality or correlations.
import seaborn as sns
sns.heatmap(data.pivot('month', 'year', 'value'))
plt.title('Heatmap')
plt.show()
Required libraries: seaborn, matplotlib, pandas
Reference: Seaborn Heatmap
Scatter Plot
Illustrative Example (SVG)
Story for Kids: If you plot your height against your age, you get a scatter plot!
Simple Tip: Scatter plots show how two things are related.
A scatter plot shows the relationship between two variables, often used for lag or cross-correlation analysis.
plt.scatter(data['x'], data['y'])
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter Plot')
plt.show()
Required library: matplotlib
Reference: Matplotlib Scatter
Decomposition Plot
Illustrative Example (SVG)
Story for Kids: It's like taking apart a toy to see all the piecesātrend, seasonality, and noise!
Simple Tip: Decomposition plots show the different parts of your data.
A decomposition plot separates a time series into trend, seasonal, and residual components.
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(data['value'], model='additive', period=12)
result.plot()
plt.show()
Required library: statsmodels, matplotlib
Reference: Forecasting: Principles and Practice
Forecast Plot
Illustrative Example (SVG)
Story for Kids: If you draw your best guess for tomorrow's temperature, that's a forecast plot!
Simple Tip: Forecast plots show your predictions and the real data together.
A forecast plot shows actual data and predicted values, often with confidence intervals.
plt.plot(data['date'], data['value'], label='Actual')
plt.plot(data['date'], forecast, label='Forecast')
plt.fill_between(data['date'], lower, upper, color='gray', alpha=0.2, label='Interval')
plt.legend()
plt.title('Forecast Plot')
plt.show()
Required library: matplotlib
Reference: Forecasting: Principles and Practice
Residual Plot
Illustrative Example (SVG)
Story for Kids: If you check how far off your guesses were from the real answer, that's a residual plot!
Simple Tip: Residual plots show the mistakes your model made.
A residual plot shows the difference between actual and predicted values over time.
plt.plot(data['date'], residuals)
plt.axhline(0, color='gray', linestyle='--')
plt.title('Residual Plot')
plt.show()
Required library: matplotlib
Reference: Forecasting: Principles and Practice
Rolling Statistics Plot
Illustrative Example (SVG)
Story for Kids: If you look at your average score over the last 5 tests, and see how it changes, that's a rolling mean plot!
Simple Tip: Rolling plots show how averages or other stats change over time.
A rolling statistics plot shows moving averages or other statistics over time.
data['rolling_mean'] = data['value'].rolling(window=12).mean()
plt.plot(data['date'], data['value'], label='Original')
plt.plot(data['date'], data['rolling_mean'], label='Rolling Mean')
plt.legend()
plt.title('Rolling Mean Plot')
plt.show()
Required library: pandas, matplotlib
Reference: Pandas Rolling
Periodogram / Spectral Plot
Illustrative Example (SVG)
Story for Kids: If you want to know which "notes" (cycles) are loudest in your data, use a periodogram!
Simple Tip: Periodograms show which cycles are strongest in your data.
A periodogram or spectral plot shows the strength of different frequencies (cycles) in your time series.
from scipy.signal import periodogram
freqs, psd = periodogram(data['value'])
plt.plot(freqs, psd)
plt.title('Periodogram / Spectral Plot')
plt.xlabel('Frequency')
plt.ylabel('Power')
plt.show()
Required libraries: scipy, matplotlib
Reference: Scipy Periodogram
QQ Plot
Illustrative Example (SVG)
Story for Kids: If you want to see if your test scores are like everyone's, you can line them up and compare!
Simple Tip: QQ plots show if your data looks like a normal (bell curve) shape.
A QQ plot compares the distribution of your data to a theoretical distribution (like normal).
import scipy.stats as stats
import matplotlib.pyplot as plt
stats.probplot(data['value'], dist="norm", plot=plt)
plt.title('QQ Plot')
plt.show()
Required libraries: scipy, matplotlib
Reference: Scipy QQ Plot
Violin Plot
Illustrative Example (SVG)
Story for Kids: A violin plot looks like a squished balloon and shows where your data is thick or thin!
Simple Tip: Violin plots show the shape and spread of your data.
A violin plot combines a boxplot and a density plot to show the distribution of your data.
import seaborn as sns
sns.violinplot(y=data['value'])
plt.title('Violin Plot')
plt.show()
Required libraries: seaborn, matplotlib
Reference: Seaborn Violin Plot
Pair Plot
Illustrative Example (SVG)
Story for Kids: If you want to see how all your test scores relate to each other, you can look at every pair!
Simple Tip: Pair plots show all the relationships between many variables.
A pair plot shows scatter plots for every pair of variables in your data.
import seaborn as sns
sns.pairplot(data)
plt.show()
Required libraries: seaborn, matplotlib
Reference: Seaborn Pair Plot
Calendar Heatmap
Illustrative Example (SVG)
Story for Kids: A calendar heatmap is like a colorful calendar that shows how busy or quiet each day was!
Simple Tip: Calendar heatmaps show patterns by day, week, or month.
A calendar heatmap visualizes daily data over months or years, highlighting patterns.
import calmap
import matplotlib.pyplot as plt
calmap.calendarplot(data['value'])
plt.title('Calendar Heatmap')
plt.show()
Required libraries: calmap, matplotlib
Reference: Calmap
Correlation Matrix Heatmap
Illustrative Example (SVG)
Story for Kids: If you want to see which of your friends are most alike, you can compare everyone to everyone!
Simple Tip: Correlation heatmaps show how much things are related.
A correlation matrix heatmap shows the correlation between all pairs of variables.
import seaborn as sns
sns.heatmap(data.corr(), annot=True, cmap='coolwarm')
plt.title('Correlation Matrix Heatmap')
plt.show()
Required libraries: seaborn, matplotlib, pandas
Reference: Seaborn Heatmap
Andrews Curves
Illustrative Example (SVG)
Story for Kids: Andrews curves are like drawing a squiggly line for each friend to see who is most similar!
Simple Tip: Andrews curves help you see groups in your data.
Andrews curves plot each row of your data as a curve, useful for visualizing clusters.
from pandas.plotting import andrews_curves
andrews_curves(data, 'class_column')
plt.title('Andrews Curves')
plt.show()
Required libraries: pandas, matplotlib
Reference: Pandas Andrews Curves
Parallel Coordinates Plot
Illustrative Example (SVG)
Story for Kids: If you want to see how your scores in different subjects compare, you can draw a line for each subject!
Simple Tip: Parallel coordinates show many variables at once.
Parallel coordinates plot each variable on a separate axis, showing patterns across many variables.
from pandas.plotting import parallel_coordinates
parallel_coordinates(data, 'class_column')
plt.title('Parallel Coordinates Plot')
plt.show()
Required libraries: pandas, matplotlib
Reference: Pandas Parallel Coordinates
Step Plot
Illustrative Example (SVG)
Story for Kids: If your allowance goes up in steps, a step plot shows each jump!
Simple Tip: Step plots show sudden changes or jumps in your data.
A step plot shows data that changes in jumps, not smoothly.
plt.step(data['date'], data['value'])
plt.title('Step Plot')
plt.show()
Required library: matplotlib
Reference: Matplotlib Step Plot
Area Plot
Illustrative Example (SVG)
Story for Kids: If you color under your line plot, you get an area plot!
Simple Tip: Area plots show how much there is over time.
An area plot fills the space under a line plot, showing cumulative totals or stacked values.
data['value'].plot.area()
plt.title('Area Plot')
plt.show()
Required libraries: pandas, matplotlib
Reference: Pandas Area Plot
Cumulative Sum Plot
Illustrative Example (SVG)
Story for Kids: If you keep adding your scores together, you get a cumulative sum plot!
Simple Tip: Cumulative plots show the total as it grows over time.
A cumulative sum plot shows the running total of your data over time.
data['cumsum'] = data['value'].cumsum()
plt.plot(data['date'], data['cumsum'])
plt.title('Cumulative Sum Plot')
plt.show()
Required libraries: pandas, matplotlib
Reference: Pandas Cumsum
Waterfall Plot
Illustrative Example (SVG)
Story for Kids: A waterfall plot shows how each step adds up to the total, like building a tower block by block!
Simple Tip: Waterfall plots show how each change adds up to the final result.
A waterfall plot shows how sequential positive and negative values lead to a final total.
import waterfall_chart
waterfall_chart.plot(data['labels'], data['values'])
plt.title('Waterfall Plot')
plt.show()
Required libraries: waterfall_chart, matplotlib
Reference: Waterfall Chart
Polar Plot
Illustrative Example (SVG)
Story for Kids: A polar plot is like drawing your data in a circle, like a clock!
Simple Tip: Polar plots show patterns that repeat in cycles.
A polar plot displays data in a circular format, useful for showing cycles or directions.
plt.subplot(projection='polar')
plt.plot(theta, r)
plt.title('Polar Plot')
plt.show()
Required library: matplotlib
Reference: Matplotlib Polar Plot
Sunburst Plot
Illustrative Example (SVG)
Story for Kids: A sunburst plot is like a colorful pie with many layers, showing how things are grouped!
Simple Tip: Sunburst plots show how data is split into groups and subgroups.
A sunburst plot visualizes hierarchical data as concentric circles.
import plotly.express as px
fig = px.sunburst(data, path=['group', 'subgroup'], values='value')
fig.show()
Required library: plotly
Reference: Plotly Sunburst
Treemap
Illustrative Example (SVG)
Story for Kids: A treemap is like a box of chocolates, where each piece shows how big or small something is!
Simple Tip: Treemaps show the size of groups in your data.
A treemap displays hierarchical data as nested rectangles, sized by value.
import plotly.express as px
fig = px.treemap(data, path=['group', 'subgroup'], values='value')
fig.show()
Required library: plotly
Reference: Plotly Treemap
Dendrogram
Illustrative Example (SVG)
Story for Kids: A dendrogram is like a family tree for your data, showing how things are related!
Simple Tip: Dendrograms show how data can be grouped into clusters.
A dendrogram is a tree diagram used to show the arrangement of clusters in hierarchical clustering.
from scipy.cluster.hierarchy import dendrogram, linkage
Z = linkage(data, 'ward')
dendrogram(Z)
plt.title('Dendrogram')
plt.show()
Required libraries: scipy, matplotlib
Reference: Scipy Dendrogram
Fan Chart
Illustrative Example (SVG)
Story for Kids: A fan chart is like a weather forecast that shows a wider and wider area for where the weather might be!
Simple Tip: Fan charts show forecast uncertainty as a "fan" of possible futures.
A fan chart shows the forecast and its uncertainty, with wider bands for more uncertain futures.
import matplotlib.pyplot as plt
plt.plot(dates, forecast, label='Forecast')
plt.fill_between(dates, lower, upper, color='blue', alpha=0.2, label='Uncertainty')
plt.title('Fan Chart')
plt.legend()
plt.show()
Required library: matplotlib
Reference: Fan Charts
Spaghetti Plot
Illustrative Example (SVG)
Story for Kids: Imagine drawing lots of lines for different friends' predictions on the same chart. It looks like spaghetti!
Simple Tip: Spaghetti plots show many possible future paths or scenarios.
A spaghetti plot overlays many time series or forecast paths to show variability or ensemble predictions.
for forecast in forecasts:
plt.plot(dates, forecast, alpha=0.3)
plt.title('Spaghetti Plot')
plt.show()
Required library: matplotlib
Reference: Spaghetti Plots
Change Point Detection Plot
Illustrative Example (SVG)
Story for Kids: Imagine your toy car suddenly changes direction. A change point plot shows where things change suddenly!
Simple Tip: Change point plots show where the data's pattern changes.
Change point detection plots highlight where the statistical properties of a time series change.
import ruptures as rpt
rpt.display(signal, bkps)
plt.title('Change Point Detection')
plt.show()
Required library: ruptures
Reference: Ruptures Change Point Detection
Forecast Error Distribution Plot
Illustrative Example (SVG)
Story for Kids: This plot is like checking how far your guesses were from the real answer!
Simple Tip: These plots show how good or bad your predictions were.
Forecast error distribution plots show the spread of errors between predicted and actual values.
import matplotlib.pyplot as plt
plt.hist(errors, bins=30)
plt.title('Forecast Error Distribution')
plt.xlabel('Error')
plt.ylabel('Frequency')
plt.show()
Required library: matplotlib
Reference: Forecast Accuracy
Time Series Matrix Plot
Illustrative Example (SVG)
Story for Kids: Imagine lots of little charts in a grid, each showing a different friend's story!
Simple Tip: Matrix plots show many time series at once.
A time series matrix plot shows multiple series as small multiples, useful for panel data.
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows, ncols, figsize=(12,8))
for i, ax in enumerate(axes.flat):
ax.plot(data[i])
plt.tight_layout()
plt.show()
Required library: matplotlib
Reference: Seaborn FacetGrid
Stacked Area Plot
Illustrative Example (SVG)
Story for Kids: It's like stacking colored sand in a bottleāeach color shows a different part!
Simple Tip: Stacked area plots show how parts add up over time.
A stacked area plot shows how multiple series contribute to a total over time.
plt.stackplot(dates, series1, series2, series3)
plt.title('Stacked Area Plot')
plt.show()
Required library: matplotlib
Reference: Matplotlib Stacked Area
Dynamic Time Warping (DTW) Alignment Plot
Illustrative Example (SVG)
Story for Kids: DTW is like matching two songs that go at different speeds, so they line up!
Simple Tip: DTW plots show how two series can be aligned even if they go at different speeds.
DTW alignment plots show how two time series are matched up, even if they are stretched or compressed in time.
from dtaidistance import dtw
alignment = dtw.warping_path(series1, series2)
dtw.visualisation.plot_warping(series1, series2, alignment)
plt.show()
Required library: dtaidistance
Reference: DTW Alignment
Time Series Clustering Plot
Illustrative Example (SVG)
Story for Kids: Clustering is like grouping your toys by color or size!
Simple Tip: Clustering plots show which series are similar to each other.
Time series clustering plots show groups of similar time series, often using color or position.
from tslearn.clustering import TimeSeriesKMeans
model = TimeSeriesKMeans(n_clusters=3)
labels = model.fit_predict(data)
for i in range(3):
plt.plot(data[labels==i].T, alpha=0.3)
plt.title('Time Series Clustering')
plt.show()
Required library: tslearn
Reference: tslearn Clustering
Autoregressive Coefficient Plot
Illustrative Example (SVG)
Story for Kids: This plot is like showing how much each friend helped you with your homework!
Simple Tip: AR coefficient plots show the importance of past values in predicting the future.
Autoregressive coefficient plots show the weights of past lags in an AR model.
from statsmodels.tsa.ar_model import AutoReg
model = AutoReg(data, lags=4).fit()
plt.bar(range(1,5), model.params[1:])
plt.title('AR Coefficient Plot')
plt.show()
Required library: statsmodels
Reference: Statsmodels AutoReg
Network/Graph Plot for Causality
Illustrative Example (SVG)
Story for Kids: This plot is like drawing arrows to show which friend started the game!
Simple Tip: Network plots show which series might cause changes in others.
Network/graph plots for causality show relationships (like Granger causality) between multiple time series.
import networkx as nx
G = nx.DiGraph()
G.add_edge('A', 'B')
nx.draw(G, with_labels=True)
plt.title('Causality Network')
plt.show()
Required library: networkx
Reference: Granger Causality