Saturday , December 21 2024
Introduction to Matplotlib

Introduction to Matplotlib

User Rating: 1.18 ( 2 votes)
1. Introduction to Matplotlib

What Is Python Matplotlib?

  1. Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
  2. Matplotlib was created by John D. Hunter.
  3. Matplotlib is open source and we can use it freely.

Matplotlib is mostly written in python, a few segments are written in C, Objective-C and Javascript for Platform compatibility. matplotlib.pyplot is a plotting library used for 2D graphics in python programming language. It can be used in python scripts, shell, web application servers and other graphical user interface toolkits.

Python Matplotlib : Types of Plots

There are various plots which can be created using python matplotlib. Some of them are listed below:

image.png

Documentation :

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

matplotlib.pyplot is a collection of command style functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.

Matplotlib Instalation

In [ ]:
pip install matplotlib

Importing pyplot

  • from matplotlib import pyplot as plt
    or
  • import matplotlib.pyplot as plt
In [2]:
import matplotlib
print(matplotlib.__version__)
3.0.2

Available Style

In [3]:
import matplotlib.pyplot as plt
plt.style.available
Out[3]:
['bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn-bright',
 'seaborn-colorblind',
 'seaborn-dark-palette',
 'seaborn-dark',
 'seaborn-darkgrid',
 'seaborn-deep',
 'seaborn-muted',
 'seaborn-notebook',
 'seaborn-paper',
 'seaborn-pastel',
 'seaborn-poster',
 'seaborn-talk',
 'seaborn-ticks',
 'seaborn-white',
 'seaborn-whitegrid',
 'seaborn',
 'Solarize_Light2',
 'tableau-colorblind10',
 '_classic_test']

Format Strings

A format string consists of a part for color, marker and line:

fmt = '[marker][line][color]'

Markers

character description
. point marker
, pixel marker
o circle marker
v triangle_down marker
^ triangle_up marker
< triangle_left marker
> triangle_right marker
1 tri_down marker
2 tri_up marker
3 tri_left marker
4 tri_right marker
s square marker
p pentagon marker
* star marker
h hexagon1 marker
H hexagon2 marker
+ plus marker
x x marker
D diamond marker
d thin_diamond marker
vline marker
_ hline marker

Line Styles

character description
solid line style
dashed line style
-. dash-dot line style
: dotted line style
Example format strings:
b blue markers with default shape
or red circles
-g green solid line
dashed line with default color
^k: black triangle_up markers connected by a dotted line

Colors

The supported color abbreviations are the single letter codes

character color
b blue
g green
r red
c cyan
m magenta
y yellow
k black
w white

About Machine Learning

Check Also

Groupby in Pandas - Data Science Tutorials

Groupby in Pandas – Data Science Tutorials

14- Groupby Groupby in Pandas¶Pandas groupby is used for grouping the data according to the …

Leave a Reply

Your email address will not be published. Required fields are marked *