Want to learn Data Visualization using Matplotlib? Hello friends, in the previous blog post we have to see basic pandas library Numpy and pandas so it’s time to see Data viasualization in python using Matplotlib. so first upon what is matplotlib ? let’s start. Matplotlib is the grandfathers library of data visualizations with Python. It was created by the John Hunter. He created it to try to replicate MatLab(another programming language) plotting capabilities in Pythons. So if you happen to be familiar with matlab, matplotlibs will feel natural to you.
It is an excellent 2D and 3D graphic library for generating scientific figures.
fig 01)Matplotlib for Data Visualization python
Some of the major Pros of Matplotlibs are:
Generally easy to started for simple plot
Support for custom labels and text
Great control of every element in a figures
High-quality output in many formats
Very customizable in general
Matplotlib allows you to create reproducible figures programmatically. Let’s learn how to use it! Before continuing this lecture, I encourage you just to explore the official Matplotlib web page: http://matplotlib.org/
You’ll need to install matplotlib first with either:
conda install matplotlib
or pip install matplotlib
Creating a subplot will delete any pre-existing subplots that overlaps with it beyond sharing a boundary.
import matplotlib.pyplot as plt
# plot a lines, implicitly creating a subplot(111)
# now create a subplots which represents the top plot of a grid with 2 rows and 1 column.
#Since this subplots will overlap the first, the plot (and its axes) previously
created, will be removed
plt.subplot(212, facecolor='y')# create 2nd subplots with yellow background
The above line produce the following outputs −
Following code plots a histogram of marks obtained by students in class. Four bins, 0-25, 26-50, 51-74 are defined.
from matplotlib import pyplot as plt
import numpy as np
fig,ax = plt.subplots(1,1)
a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
ax.hist(a, bins =[0,25,50,75,100])
ax.set_title("histogram of result")
ax.set_ylabel('no. of students')
The plot appears as shown below −
Tags:Matplotlib for Data Visualization python- tutorials