Skip to content

Introducing Matplotlib #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added contrib/plotting-visualization/images/barplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions contrib/plotting-visualization/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# List of sections

- [Installing Matplotlib](matplotlib-installation.md)
- [Introducing Matplotlib](matplotlib-introduction.md)
- [Bar Plots in Matplotlib](matplotlib-bar-plots.md)
- [Pie Charts in Matplotlib](matplotlib-pie-charts.md)
80 changes: 80 additions & 0 deletions contrib/plotting-visualization/matplotlib-introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Introducing MatplotLib

Data visualisation is the analysing and understanding the data via graphical representation of the data by the means of pie charts, histograms, scatterplots and line graphs.

To make this process of data visualization easier and clearer, matplotlib library is used.

## Features of MatplotLib library
- MatplotLib library is one of the most popular python packages for 2D representation of data
- Combination of matplotlib and numpy is used for easier computations and visualization of large arrays and data. Matplotlib along with NumPy can be considered as the open source equivalent of MATLAB.

- Matplotlib has a procedural interface named the Pylab, which is designed to resemble MATLAB. However, it is completely independent of Matlab.

## Starting with Matplotlib

### 1. Install and import the neccasary libraries - mayplotlib.pylplot

```bash
pip install matplotlib
```

```python
import maptplotlib.pyplot as plt
import numpy as np
```

### 2. Scatter plot
Scatter plot is a type of plot that uses the cartesian coordinates between x and y to describe the relation between them. It uses dots to represent relation between the data variables of the data set.

```python
x = [5,4,5,8,9,8,6,7,3,2]
y = [9,1,7,3,5,7,6,1,2,8]

plt.scatter(x,y, color = "red")

plt.title("Scatter plot")
plt.xlabel("X values")
plt.ylabel("Y values")

plt.tight_layout()
plt.show()
```

![scatterplot](images/scatterplot.png)

### 3. Bar plot
Bar plot is a type of plot that plots the frequency distrubution of the categorical variables. Each entity of the categoric variable is represented as a bar. The size of the bar represents its numeric value.

```python
x = np.array(['A','B','C','D'])
y = np.array([42,50,15,35])

plt.bar(x,y,color = "red")

plt.title("Bar plot")
plt.xlabel("X values")
plt.ylabel("Y values")

plt.show()
```

![barplot](images/barplot.png)

### 4. Histogram
Histogram is the representation of frequency distribution of qualitative data. The height of each rectangle defines the amount, or how often that variable appears.

```python
x = [9,1,7,3,5,7,6,1,2,8]

plt.hist(x, color = "red", edgecolor= "white", bins =5)

plt.title("Histogram")
plt.xlabel("X values")
plt.ylabel("Frequency Distribution")

plt.show()
```

![histogram](images/histogram.png)