8 Types of Plots for Time Series Analysis using Python
Last Updated :
28 Apr, 2025
Time series data
Time series data is a collection of observations chronologically arranged at regular time intervals. Each observation corresponds to a specific time point, and the data can be recorded at various frequencies (e.g., daily, monthly, yearly). This type of data is very essential in many fields, including finance, economics, climate science, and others as it helps to grasp underlying patterns, spot trends, and spot seasonal fluctuations by analyzing time series data.
What is Time Series Analysis?
Techniques for evaluating time-series data to determine relevant statistics and other data properties are referred to as time series analysis. Any time series with a recurrent pattern, including those in the financial markets, the weather, and social media statistics, can be subjected to it. The primary goal of time series analysis is to investigate key ideas concerning market trends and economic cycles.
Visualizations are vital in the process of obtaining insightful information from time series data and enable us to comprehend complex relationships and make intelligent decisions.
This article covers several types of plots that will help you with time series analysis using Python, with detailed examples using a freely accessible dataset.
Dataset description
What are Sunspots?
Sunspots are areas of the Sun's surface, known as the photosphere, where the magnetic field is concentrated and results in reduced surface temperature compared to its surroundings. The complex magnetic activity of the Sun is what generates these black areas.
Sunspots have been observed and documented for many years, some of the earliest records being from ancient civilizations. Understanding solar behavior, space weather, and their possible impacts on the climate and communication systems of Earth is greatly aided by their research. Sunspots are still being studied by scientists to learn more about the dynamics of the Sun's magnetic field and how it affects our solar system.
Dataset variables: The dataset consists of 2 columns - "Month" and "Sunspots" from 1749 to 1983. It basically describes the number of sunspots that were seen on the sun each month was recorded in this dataset.
Let's begin coding now!
Importing necessary libraries
Python3
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.graphics.tsaplots import plot_acf
from statsmodels.graphics.tsaplots import plot_pacf
Importing the dataset
Python3
# Load the Monthly Sunspots dataset
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/monthly-sunspots.csv"
data = pd.read_csv(url, parse_dates=['Month'], index_col='Month')
print(data)
Output:
Sunspots
Month
1749-01-01 58.0
1749-02-01 62.6
1749-03-01 70.0
1749-04-01 55.7
1749-05-01 85.0
... ...
1983-08-01 71.8
1983-09-01 50.3
1983-10-01 55.8
1983-11-01 33.3
1983-12-01 33.4
[2820 rows x 1 columns]
Now, we can start understanding various types of plot along with their implementation in Python.
Types of Plots
1. Time Plot
One of the most basic representations of time series data is the time plot, sometimes called a time series plot. The x-axis is time, and the y-axis is the relevant variable, and it shows data points in chronological order.
The temporal plot is utilized in this research to show the monthly fluctuation in sunspot numbers across the complete dataset period from 1749 to 1983. We can learn more about the overall trend, seasonal trends, and any potential outliers or abnormalities in the sunspot data by looking at the time map.
Here is a code example of a time plot
Python3
# Time plot
plt.figure(figsize=(7, 5))
plt.plot(data.index, data['Sunspots'], marker='o', linestyle='-', markersize=5)
plt.xlabel('Date')
plt.ylabel('Number of Sunspots')
plt.title('Monthly Sunspots Time Plot')
plt.grid(True)
plt.show()
Output:
.png)
Over the full dataset period, the time plot displays the monthly variance in the number of sunspots. Here, the highest number of sunspots occurred around 1960, while the lowest around 1800.
2. Line Plot
A simple visualization that links data points with straight lines is known as a line plot. A continuous view of the time series data is provided, emphasizing the trend and changes in the variable over time. It is mainly used to track the long-term patterns in the data.
The line plot is employed in our study to display the long-term trends in the number of sunspots seen on the sun. This enables us to determine the general trend of sunspot activity and whether the number of sunspots is rising, falling, or staying the same over time.
let's plot it using python now
Python3
# Line plot
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 5))
plt.plot(data)
plt.xlabel('Date')
plt.ylabel('Number of Sunspots')
plt.title('Monthly Sunspots Line Plot')
plt.grid(True)
plt.show()
Output:
.png)
Now, time plot and line plot look almost the same, however it is important to note that a line plot is a general term for a plot that displays the relationship between two continuous variables, without any specific emphasis on time.
On the other hand, a time plot is a specialized form of a line plot that focuses on visualizing how a variable changes over time, with time being the x-axis variable. Time plots are particularly useful when dealing with time series data, where observations are ordered chronologically and recorded at regular time intervals.
3. Seasonal Plot
The seasonal plot breaks down time series data into seasonal components to illustrate patterns that reoccur over predetermined time intervals, such as annual or monthly cycles. It enables us to recognize recurring trends in sunspot activity, such as variations in activity throughout the year.
Here is a code example of a seasonal plot
Python3
# Seasonal plot
plt.figure(figsize=(7, 5))
sns.lineplot(x=data.index.month, y=data['Sunspots'], ci=None)
plt.xlabel('Month')
plt.ylabel('Number of Sunspots')
plt.title('Seasonal Plot')
plt.xticks(range(1, 13), labels=[
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
plt.grid(True)
plt.show()
Output:
.png)
From this seasonal plot, we can learn more about the seasonality of solar activity which reveals the months that tend to have higher or lower sunspot activity.
4. Histogram and Density Plot
A density plot is defined as a graphical representation which is used to visualize the distribution of data and estimate the probability density function (PDF) of a continuous random variable. It is basically a smoothed version of a histogram, providing a continuous curve that represents the underlying data distribution. These plots are suitable when dealing with large datasets or when a smooth, continuous representation of the data is needed to shed light on how values are distributed throughout the time series.
Here is a code example of a histogram and density plot
Python3
# Histogram and Density Plot
plt.figure(figsize=(7, 5))
sns.histplot(data['Sunspots'], kde=True)
plt.xlabel('Number of Sunspots')
plt.ylabel('Frequency')
plt.title('Histogram and Density Plot')
plt.grid(True)
plt.show()
Output:
.png)
The density plot and histogram show the frequency distribution of the number of sunspots, which aids in our comprehension of the form of the sunspot distribution and its central tendency.
5. Autocorrelation Plot
Autocorrelation plot, also known as a correlogram is defined as a time series analysis tool used to display the autocorrelation of a time series with itself at various lags. The link between a data point and its prior observations at various time lags is measured by autocorrelation. It basically represents the correlation between a time series and its own lagged values. The plots are mainly used for identifying the seasonal lags in the data
Let's plot an autocorrelation plot using python now
Python3
# Autocorrelation Plot
plt.figure(figsize=(7,5))
plot_acf(data['Sunspots'], lags=50)
plt.xlabel('Lags')
plt.ylabel('Autocorrelation')
plt.title('Autocorrelation Plot')
plt.grid(True)
plt.show()
Output:
.png)
The autocorrelation plot displays the correlation at different lags, which is useful for understanding the seasonal patterns in sunspot activity. A substantial autocorrelation at particular delays suggests that sunspot activity may follow a yearly pattern.
6. Partial Autocorrelation Function (PACF) Plot
The Partial Autocorrelation Function (PACF) plot is a graphical tool used in time series analysis to determine the autoregressive (AR) order of a time series. While accounting for the effects of all intermediate delays, it displays the direct influence of each lag on the time series' current value. Basically, it examines the correlation between a data point and its prior observations without taking into account the effect of the intervening time steps.
Here is a code example of a partial autocorrelation function (PACF) plot
Python3
# PACF plot
plt.figure(figsize=(7, 5))
plot_pacf(data['Sunspots'], lags=50)
plt.xlabel('Lags')
plt.ylabel('Partial Autocorrelation')
plt.title('Partial Autocorrelation Function (PACF) Plot')
plt.grid(True)
plt.show()
Output:
.png)
In our approach, the number of lag observations with a substantial influence on the current sunspot count is determined using the PACF plot. The PACF aids in choosing the AR model's forecasting order for sunspot activity.
7. Polar Plot
A polar plot is a data visualization plot in which the data points are arranged in a circular pattern. The angle around the circle and the radial distance from the center are used to represent various variables or data properties. These are mainly used for visualizing the seasonal patterns in a data set.
Here is a code example of a polar plot
Python3
# Extracting the month and year from the index of the above dataset "Monthly Sunspots"
data['Month_Num'] = data.index.month
# Grouping the data by month, calculating the average number of sunspots for each month
monthly_average = data.groupby('Month_Num')['Sunspots'].mean()
# Polar Plot theta (angle) and radii (length) settings
theta = np.linspace(0, 2 * np.pi, len(monthly_average))
radii = monthly_average.values
# Polar Plot
plt.figure(figsize=(7, 5))
plt.polar(theta, radii)
plt.title('Polar Plot of Monthly Average Sunspots')
plt.xticks(theta, ['Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
# Set y-axis limit to accommodate the data
plt.ylim(0, radii.max() + 10)
plt.show()
Output:
.png)
The polar plot in this particular case displays the average number of sunspots every month. The radial distance from the center reflects the average number of sunspots for each month, while the angular location within the circle represents the months (e.g., January, February, March, etc.). It reveals any seasonal tendencies present in the data and allows us to see cyclic patterns in the annual cycle of sunspot activity.
The monthly average sunspot view is captivatingly displayed in the polar plot, which also reveals cyclical trends throughout the year.
8. Moving Average Plot
In time series analysis, a Moving average plot is a popular data visualization approach for spotting trends and patterns in the data. Its main objective is to eliminate short-term fluctuations and reveal long-term trends in the data by determining the average of a specified window of succeeding data points.
The data points within the window are averaged, and the resulting values are shown on a graph to generate a moving average plot. It is simpler to spot and compare trends and seasonal patterns when the Moving Average line is positioned over the original data graph.
Here is a code example of a moving average plot
Python3
# Moving Average Plot
plt.figure(figsize=(7, 5))
values = data['Sunspots']
# 7-day moving average
rolling_mean = values.rolling(window=7).mean()
plt.plot(values, label='Original')
plt.plot(rolling_mean, label='7-day Moving Average', color='red')
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('Moving Average Plot')
plt.legend()
plt.grid(True)
plt.show()
Output:
.png)
We are plotting a 7-day moving average here. We know that a moving average is a technique for smoothing data by determining the average of a predetermined window of subsequent data points. The number of data points utilized for averaging depends on the window size, commonly referred to as the moving average period. This method involves averaging the initial sunspot data over a period of seven days.
Conclusion:
By utilizing these various plots and data visualization techniques, we can gain a comprehensive understanding of the "Monthly Sunspots" dataset, identify patterns, and extract valuable insights about solar activity over several centuries.
As a result of this research, you now possess the knowledge necessary to apply these techniques to time series datasets in a variety of sectors and industries. Time series analysis provides vital tools for acquiring insightful insights and making data-driven decisions in any field requiring sequential data, including economics, finance, climate studies, and other areas. By adopting these methods, we have the ability to utilize time-dependent data and tap into its predictive potential to address real-world issues.
Similar Reads
Data Analysis (Analytics) Tutorial Data Analytics is a process of examining, cleaning, transforming and interpreting data to discover useful information, draw conclusions and support decision-making. It helps businesses and organizations understand their data better, identify patterns, solve problems and improve overall performance.
4 min read
Introduction to Data Analytics
What is Data Analytics?Data Analytics is the process of collecting, organizing and studying data to find useful information understand whatâs happening and make better decisions. In simple words it helps people and businesses learn from data like what worked in the past, what is happening now and what might happen in the
6 min read
Why Data Analysis is Important?DData Analysis involves inspecting, transforming, and modeling data to discover useful information, inform conclusions, and support decision-making. It encompasses a range of techniques and tools used to interpret raw data, identify patterns, and extract actionable insights. Effective data analysis
5 min read
Data Science vs Data AnalyticsIn this article, we will discuss the differences between the two most demanded fields in Artificial intelligence that is data science, and data analytics.What is Data Science Data Science is a field that deals with extracting meaningful information and insights by applying various algorithms preproc
3 min read
Uses of Data AnalyticsIn this article, we are going to discuss different uses of data analytics. And will discuss the application where we will see how data is an essential part of different sectors. So, let's discuss them one by one. Data is of much importance nowadays. Data helps you understand performance providing th
3 min read
Life Cycle Phases of Data AnalyticsIn this article, we are going to discuss life cycle phases of data analytics in which we will cover various life cycle phases and will discuss them one by one. Data Analytics Lifecycle :The Data analytic lifecycle is designed for Big Data problems and data science projects. The cycle is iterative to
3 min read
Data Preprocessing and Exploration
What is Data Cleaning?Data cleaning, also known as data cleansing or data scrubbing, is the process of identifying and correcting (or removing) errors, inconsistencies, and inaccuracies within a dataset. This crucial step in the data management and data science pipeline ensures that the data is accurate, consistent, and
12 min read
ML | Handling Missing ValuesMissing values are a common issue in machine learning. This occurs when a particular variable lacks data points, resulting in incomplete information and potentially harming the accuracy and dependability of your models. It is essential to address missing values efficiently to ensure strong and impar
12 min read
What is Feature Engineering?Feature engineering is the process of turning raw data into useful features that help improve the performance of machine learning models. It includes choosing, creating and adjusting data attributes to make the modelâs predictions more accurate. The goal is to make the model better by providing rele
5 min read
What is Data Transformation?Data transformation is an important step in data analysis process that involves the conversion, cleaning, and organizing of data into accessible formats. It ensures that the information is accessible, consistent, secure, and finally recognized by the intended business users. This process is undertak
6 min read
EDA - Exploratory Data Analysis in PythonExploratory Data Analysis (EDA) is a important step in data analysis which focuses on understanding patterns, trends and relationships through statistical tools and visualizations. Python offers various libraries like pandas, numPy, matplotlib, seaborn and plotly which enables effective exploration
6 min read
Univariate, Bivariate and Multivariate data and its analysisData analysis is an important process for understanding patterns and making informed decisions based on data. Depending on the number of variables involved it can be classified into three main types: univariate, bivariate and multivariate analysis. Each method focuses on different aspects of the dat
5 min read
Python - Data visualization tutorialData visualization is a crucial aspect of data analysis, helping to transform analyzed data into meaningful insights through graphical representations. This comprehensive tutorial will guide you through the fundamentals of data visualization using Python. We'll explore various libraries, including M
7 min read
Statistical Analysis and Probability
Probability Data Distributions in Data ScienceUnderstanding how data behaves is one of the first steps in data science. Before we dive into building models or running analysis, we need to understand how the values in our dataset are spread out and thatâs where probability distributions come in.Let us start with a simple example: If you roll a f
8 min read
Central Limit Theorem in StatisticsThe Central Limit Theorem in Statistics states that as the sample size increases and its variance is finite, then the distribution of the sample mean approaches normal distribution irrespective of the shape of the population distribution.The central limit theorem posits that the distribution of samp
11 min read
Parametric Methods in StatisticsParametric statistical methods are those that make assumptions regarding the distribution of the population. These methods presume that the data have a known distribution (e.g., normal, binomial, Poisson) and rely on parameters (e.g., mean and variance) to define the data.Key AssumptionsParametric t
6 min read
Non-Parametric TestsNon-parametric tests are applied in hypothesis testing when the data does not satisfy the assumptions necessary for parametric tests, such as normality or equal variances. These tests are especially helpful for analyzing ordinal data, small sample sizes, or data with outliers.Common Non-Parametric T
5 min read
ANOVA for Machine LearningANOVA is useful when we need to compare more than two groups and determine whether their means are significantly different. Suppose you're trying to understand which ingredients in a recipe affect its taste. Some ingredients, like spices might have a strong influence while others like a pinch of sal
9 min read
Confidence IntervalA Confidence Interval (CI) is a range of values that contains the true value of something we are trying to measure like the average height of students or average income of a population.Instead of saying: âThe average height is 165 cm.âWe can say: âWe are 95% confident the average height is between 1
7 min read
Hypothesis TestingHypothesis testing compares two opposite ideas about a group of people or things and uses data from a small part of that group (a sample) to decide which idea is more likely true. We collect and study the sample data to check if the claim is correct.Hypothesis TestingFor example, if a company says i
9 min read
P-Value: Comprehensive Guide to Understand, Apply, and InterpretA p-value is a statistical metric used to assess a hypothesis by comparing it with observed data. This article delves into the concept of p-value, its calculation, interpretation, and significance. It also explores the factors that influence p-value and highlights its limitations. Table of Content W
12 min read
Data Analysis Libraries & Tools
Pandas TutorialPandas is an open-source software library designed for data manipulation and analysis. It provides data structures like series and DataFrames to easily clean, transform and analyze large datasets and integrates with other Python libraries, such as NumPy and Matplotlib. It offers functions for data t
6 min read
NumPy Tutorial - Python LibraryNumPy (short for Numerical Python ) is one of the most fundamental libraries in Python for scientific computing. It provides support for large, multi-dimensional arrays and matrices along with a collection of mathematical functions to operate on arrays.At its core it introduces the ndarray (n-dimens
3 min read
Matplotlib TutorialMatplotlib is an open-source visualization library for the Python programming language, widely used for creating static, animated and interactive plots. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, Qt, GTK and wxPython. It
5 min read
Python Seaborn TutorialSeaborn is a library mostly used for statistical plotting in Python. It is built on top of Matplotlib and provides beautiful default styles and color palettes to make statistical plots more attractive.In this tutorial, we will learn about Python Seaborn from basics to advance using a huge dataset of
15+ min read
Power BI Tutorial | Learn Power BIPower BI is a Microsoft-powered business intelligence tool that helps transform raw data into interactive dashboards and actionable insights. It allow users to connect to various data sources, clean and shape data and visualize it using charts, graphs and reports all with minimal coding.Itâs widely
5 min read
Tableau TutorialTableau is a leading data visualization tool that help users to create interactive and insightful visualizations from data. With Tableau we can transform raw data into meaningful visuals without the need for coding. This tutorial will guide us through data visualization using Tableau like connecting
5 min read
SQL for Data AnalysisSQL (Structured Query Language) is a powerful tool for data analysis, allowing users to efficiently query and manipulate data stored in relational databases. Whether you are working with sales, customer or financial data, SQL helps extract insights and perform complex operations like aggregation, fi
6 min read
How to Perform Data Analysis in Excel: A Beginnerâs GuideExcel is one of the most powerful tools for data analysis, allowing you to process, manipulate, and visualize large datasets efficiently. Whether you're analyzing sales figures, financial reports, or any other type of data, knowing how to perform data analysis in Excel can help you make informed dec
14 min read
Time Series Analysis
Time Series Analysis & Visualization in PythonTime series data consists of sequential data points recorded over time which is used in industries like finance, pharmaceuticals, social media and research. Analyzing and visualizing this data helps us to find trends and seasonal patterns for forecasting and decision-making. In this article, we will
6 min read
8 Types of Plots for Time Series Analysis using PythonTime series data Time series data is a collection of observations chronologically arranged at regular time intervals. Each observation corresponds to a specific time point, and the data can be recorded at various frequencies (e.g., daily, monthly, yearly). This type of data is very essential in many
10 min read
Handling Missing Values in Time Series DataHandling missing values in time series data in R is a crucial step in the data preprocessing phase. Time series data often contains gaps or missing observations due to various reasons such as sensor malfunctions, human errors, or other external factors. In R Programming Language dealing with missing
5 min read
Understanding the Moving average (MA) in Time Series DataData is often collected with respect to time, whether for scientific or financial purposes. When data is collected in a chronological order, it is referred to as time series data. Analyzing time series data provides insights into how the data behaves over time, including underlying patterns that can
15 min read
Augmented Dickey-Fuller (ADF)Augmented Dickey-Fuller (ADF) test is a statistical test in time series analysis used to determine whether a given time series is stationary. A stationary time series has constant mean and variance over time, which is a core assumption in many time series models, including ARIMA.Why Stationarity Mat
3 min read
AutoCorrelationAutocorrelation is a fundamental concept in time series analysis. Autocorrelation is a statistical concept that assesses the degree of correlation between the values of variable at different time points. The article aims to discuss the fundamentals and working of Autocorrelation. Table of Content Wh
10 min read
Data Analytics Projects
30+ Top Data Analytics Projects in 2025 [With Source Codes]Are you an aspiring data analyst? Dive into 40+ FREE Data Analytics Projects packed with the hottest 2024 tech. Data Analytics Projects for beginners, final-year students, and experienced professionals to Master essential data analytical skills. These top data analytics projects serve as a simple ye
4 min read
Top 80+ Data Analyst Interview Questions and AnswersData is information, often in the form of numbers, text, or multimedia, that is collected and stored for analysis. It can come from various sources, such as business transactions, social media, or scientific experiments. In the context of a data analyst, their role involves extracting meaningful ins
15+ min read