|
| 1 | +# Introducing MatplotLib |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +To make this process of data visualization easier and clearer, matplotlib library is used. |
| 6 | + |
| 7 | +## Features of MatplotLib library |
| 8 | +- MatplotLib library is one of the most popular python packages for 2D representation of data |
| 9 | +- 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. |
| 10 | + |
| 11 | +- Matplotlib has a procedural interface named the Pylab, which is designed to resemble MATLAB. However, it is completely independent of Matlab. |
| 12 | + |
| 13 | +## Starting with Matplotlib |
| 14 | + |
| 15 | +### 1. Install and import the neccasary libraries - mayplotlib.pylplot |
| 16 | + |
| 17 | +```bash |
| 18 | +pip install matplotlib |
| 19 | +``` |
| 20 | + |
| 21 | +```python |
| 22 | +import maptplotlib.pyplot as plt |
| 23 | +import numpy as np |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. Scatter plot |
| 27 | +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. |
| 28 | + |
| 29 | +```python |
| 30 | +x = [5,4,5,8,9,8,6,7,3,2] |
| 31 | +y = [9,1,7,3,5,7,6,1,2,8] |
| 32 | + |
| 33 | +plt.scatter(x,y, color = "red") |
| 34 | + |
| 35 | +plt.title("Scatter plot") |
| 36 | +plt.xlabel("X values") |
| 37 | +plt.ylabel("Y values") |
| 38 | + |
| 39 | +plt.tight_layout() |
| 40 | +plt.show() |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +### 3. Bar plot |
| 46 | +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. |
| 47 | + |
| 48 | +```python |
| 49 | +x = np.array(['A','B','C','D']) |
| 50 | +y = np.array([42,50,15,35]) |
| 51 | + |
| 52 | +plt.bar(x,y,color = "red") |
| 53 | + |
| 54 | +plt.title("Bar plot") |
| 55 | +plt.xlabel("X values") |
| 56 | +plt.ylabel("Y values") |
| 57 | + |
| 58 | +plt.show() |
| 59 | +``` |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +### 4. Histogram |
| 64 | +Histogram is the representation of frequency distribution of qualitative data. The height of each rectangle defines the amount, or how often that variable appears. |
| 65 | + |
| 66 | +```python |
| 67 | +x = [9,1,7,3,5,7,6,1,2,8] |
| 68 | + |
| 69 | +plt.hist(x, color = "red", edgecolor= "white", bins =5) |
| 70 | + |
| 71 | +plt.title("Histogram") |
| 72 | +plt.xlabel("X values") |
| 73 | +plt.ylabel("Frequency Distribution") |
| 74 | + |
| 75 | +plt.show() |
| 76 | +``` |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
0 commit comments