Get Started

Add summary statistics to your time series plot

It is possible to visualize time series plots and numerical summaries on one single graph by using the pandas API to matplotlib along with the table method:

# Plot the time series data in the DataFrame
ax = df.plot()

# Compute summary statistics of the df DataFrame
df_summary = df.describe()

# Add summary table information to the plot
ax.table(cellText=df_summary.values, 
         colWidths=[0.3]*len(df.columns), 
         rowLabels=df_summary.index, 
         colLabels=df_summary.columns, 
         loc='top')

This is a part of the course

“Visualizing Time Series Data in Python”

View Course

Exercise instructions

Review meat_mean in the shell -- a DataFrame that contains the mean of all the time series in meat.

  • Assign all the values in meat_mean to the cellText argument.
  • Assign all the values in index of meat_mean to the rowLabels argument.
  • Assign the column names of meat_mean to the colLabels argument.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot the meat data
ax = meat.plot(fontsize=6, linewidth=1)

# Add x-axis labels
ax.set_xlabel('Date', fontsize=6)

# Add summary table information to the plot
ax.table(cellText=meat_mean.____,
         colWidths = [0.15]*len(meat_mean.columns),
         rowLabels=meat_mean.____,
         colLabels=meat_mean.____,
         loc='top')

# Specify the fontsize and location of your legend
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 0.95), ncol=3, fontsize=6)

# Show plot
plt.show()

This exercise is part of the course

Visualizing Time Series Data in Python

IntermediateSkill Level
4.7+
15 reviews

Visualize seasonality, trends and other patterns in your time series data.

In the field of Data Science, it is common to be involved in projects where multiple time series need to be studied simultaneously. In this chapter, we will show you how to plot multiple time series at once, and how to discover and describe relationships between multiple time series.

Exercise 1: Working with more than one time seriesExercise 2: Load multiple time seriesExercise 3: Visualize multiple time seriesExercise 4: Statistical summaries of multiple time seriesExercise 5: Plot multiple time seriesExercise 6: Define the color palette of your plotsExercise 7: Add summary statistics to your time series plot
Exercise 8: Plot your time series on individual plotsExercise 9: Find relationships between multiple time seriesExercise 10: Compute correlations between time seriesExercise 11: Visualize correlation matricesExercise 12: Clustered heatmaps

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free