# Ploting with Matplotlib.pyplot¶

Ha Khanh Nguyen (hknguyen)

## 1. Install a New Module¶

• Before you can import a module to Python, you have to first install it. Like before you open a software on your computer, you first need to install it on your computer.
• We didn't have to install pandas in the previous video because we already did that when we worked on lab01!
• But with this new module, Matplotlib.pyplot, we have to first install it:

• Open your command prompt (Terminal for Mac users, Anaconda Prompt for Windows users)
• Type the following command then press Enter:

conda install matplotlib
• You only need to install a module ONCE on a computer! Sometimes, you need to update a module if new version comes out!
conda update <module name>

## 2. Histogram¶

• The first plot we will learn to conduct is a histogram!
• First, import the module we need, which is Matplotlib.pyplot in this case:
• Now, before we can plot a histogram, we need to first get some data! Let's use pandas to load a dataset to Python.
• We're ready to plot our first histogram!
• So what are the colors available to choose?

• Plots do not make sense without axis labels!
• To add an x-axis label in Python, use plt.xlable():
• Similarly, use plt.ylabel() to add a y-axis label:

### 2.3 Changing number of bins¶

• Histogram can look very different depending on the number of bins used to plot the histogram!

## 3. Boxplot¶

• Use plt.boxplot() to plot a boxplot:

### 3.1 Horizontal boxplot¶

• What's if you want the boxplot to be horizontal instead?

### 3.2 Add variable name & axis label¶

• Just like with histogram, we can add axis label to boxplot! It might also be a good idea to add variable name (also called label) to the boxplot.
• Adding variable names is especially important when you're plotting multiple variables in the same plot!

## 4. Scatterplot¶

• Scatterplot is one of the most important plots in Statistics! We plot scatterplot in Matplotlib using plt.scatter():
• Now, let's add axis labels and change the colors!