Dataslope logoDataslope

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.

Code Block
Python 3.13.2

Plotly recognizes date as a datetime column and gives you a range slider if you ask:

Code Block
Python 3.13.2

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:

Code Block
Python 3.13.2

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.

Code Block
Python 3.13.2

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

  1. 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.
  2. 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.
  3. Calendar vs business time. For stock prices, you may want to skip weekends and holidays — set fig.update_xaxes(rangebreaks=[dict(bounds=["sat", "mon"])]).
  4. Day-of-week effects. Most business data has strong weekly seasonality. Don't compute a "trend" without considering it.
  5. 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

Code Block
Python 3.13.2

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):

Code Block
Python 3.13.2

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

QuestionSelect one

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.

QuestionSelect one

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.

QuestionSelect one

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.

QuestionSelect one

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.

On this page