Time Series Visualization
Special patterns and pitfalls for data with a time dimension
Time-series data — anything indexed by date or timestamp — is the most common kind of data in business and science. It deserves its own chapter because:
- Time has structure (years, months, weeks, hours, holidays, seasons).
- The eye reads horizontal-time charts very fluently.
- A handful of specific pitfalls are unique to time series.
The default: a line chart with time on x
For evenly-spaced, continuous time data, a line chart with x = time is almost always the right starting point.
Plotly recognizes date as a datetime column and gives you a
range slider if you ask:
Drag the slider below the chart to zoom into any time window.
Resampling: aggregating to a more useful granularity
Raw time-series data is often too granular for the chart you want.
You may have per-minute data but want to see daily trends.
Pandas' .resample() is the workhorse:
Resampling is the "zoom level" of time analysis: minute, hour, day, week, month, quarter, year. Pick the level that matches the story you're telling.
Moving averages: smoothing noisy series
A common pattern: the data is noisy day-to-day but has a clear weekly or monthly trend. A moving average smooths the line so the trend is visible.
The 30-day average is the smoothest and reveals the underlying trend; the 7-day catches weekly structure; the raw daily shows the noise. All three layered gives the whole story.
Common time-series pitfalls
- Non-monotonic x-axis. If your DataFrame isn't sorted by
date, the line wiggles backwards through time. Always
df.sort_values("date")before plotting. - Inconsistent time gaps. A daily chart that's missing weekends becomes misleading — Plotly will interpolate across the gap as if Saturday's value smoothly became Monday's.
- Calendar vs business time. For stock prices, you may want
to skip weekends and holidays — set
fig.update_xaxes(rangebreaks=[dict(bounds=["sat", "mon"])]). - Day-of-week effects. Most business data has strong weekly seasonality. Don't compute a "trend" without considering it.
- Axis truncation can be more justified. For time series showing change, starting the y-axis at a non-zero value is sometimes acceptable — but always label it clearly.
Skipping non-trading days
Notice the x-axis no longer has flat "no movement" stretches over weekends.
Seasonal patterns: faceting by year
To compare years on the same calendar, facet by year (or use a year-over-year plot where the x-axis is just month/day):
Facets are excellent for time series too — they let you see each group's shape clearly, and shared axes ensure honest comparison.
Check your understanding
What is .resample('D').mean() on a pandas time-indexed DataFrame doing?
Sorting the data alphabetically.
Filling missing values.
Aggregating the data to daily frequency, computing the mean of all rows that fall in each day.
Duplicating each row.
Why is a moving average often useful for noisy daily time-series data?
It increases the data resolution.
It is required by Plotly.
It smooths short-term noise so the underlying weekly or monthly trend becomes visible.
It removes outliers.
If your line chart's x-axis is a date and the line zigzags backward in time, what is the most likely cause?
The DataFrame contains negative values.
The dates are in the wrong time zone.
The DataFrame is not sorted by date — Plotly draws lines in DataFrame row order, not date order.
The y-axis is on a log scale.
Which Plotly chart configuration hides weekend gaps in a stock-price line chart, so the x-axis only shows trading days?
Filtering the DataFrame to weekdays only.
fig.update_layout(weekends=False).
fig.update_xaxes(rangebreaks=[dict(bounds=["sat", "mon"])]).
This isn't possible in Plotly.