0% found this document useful (0 votes)
15 views

Matplotlibgig

This tutorial discusses creating line plots, bar plots, and scatter plots in Matplotlib using stock market data from 2022. Matplotlib is a powerful and popular Python library for data visualization. The tutorial focuses on customizing plots through color, labels, and organization to tell compelling stories from data.

Uploaded by

rahul.mani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Matplotlibgig

This tutorial discusses creating line plots, bar plots, and scatter plots in Matplotlib using stock market data from 2022. Matplotlib is a powerful and popular Python library for data visualization. The tutorial focuses on customizing plots through color, labels, and organization to tell compelling stories from data.

Uploaded by

rahul.mani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Matplotlib is a powerful and very popular data visualization library in Python.

In this
tutorial, we will discuss how to create line plots, bar plots, and scatter plots in
Matplotlib using stock market data in 2022. These are the foundational plots that will
allow you to start understanding, visualizing, and telling stories about data. Data
visualization is an essential skill for all data analysts and Matplotlib is one of the most
popular libraries for creating visualizations.

This tutorial expects some basic prior knowledge in NumPy arrays and pandas
dataframes. When we use those libraries, we will quickly explain what we are doing.
The main focus of this tutorial is Matplotlib, which works on top of these data
structures to create visualizations.

Matplotlib is very flexible and customizable for creating plots. It does require a lot of
code to make more basic plots with little customizations. When working in a setting
where exploratory data analysis is the main goal, requiring many quickly drawn plots
without as much emphasis on aesthetics, the library seaborn is a great option as it
builds on top of Matplotlib to create visualizations more quickly. Please see
our Python Seaborn Tutorial For Beginners instead if exploratory data analysis or
quick and easy graph creation is your main priority.

Matplotlib Examples
By the end of this tutorial, you will be able to make great-looking visualizations in
Matplotlib. We will focus on creating line plots, bar plots, and scatter plots. We will also
focus on how to make customization decisions, such as the use of color, how to label
plots, and how to organize them in a clear way to tell a compelling story.
The Dataset
Matplotlib is designed to work with NumPy arrays and pandas dataframes. The library
makes it easy to make graphs from tabular data. For this tutorial, we will use the Dow
Jones Industrial Average (DJIA) index’s historical prices from 2022-01-01 to 2022-12-
31 (found here). You can set the date range on the page and then click the “download a
spreadsheet” button.

We will load in the csv file, named HistoricalPrices.csv using the pandas library and view the
first rows using the .head() method.

import pandas as pd

djia_data = pd.read_csv('HistoricalPrices.csv')
djia_data.head()

OpenAI

We see the data include 4 columns, a Date, Open, High, Low, and Close. The latter 4 are
related to the price of the index during the trading day. Below is a brief explanation of
each variable.

• Date: The day that the stock price information represents.


• Open: The price of the DJIA at 9:30 AM ET when the stock market
opens.
• High: The highest price the DJIA reached during the day.
• Low: The lowest price the DJIA reached during the day.
• Close: The price of the DJIA when the market stopped trading at 4:00
PM ET.
As a quick clean up step, we will also need to use the rename() method in pandas as the
dataset we downloaded has an extra space in the column names.

You might also like