What Is Python Matplotlib?¶
- Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
- Matplotlib was created by John D. Hunter.
- 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:
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¶
pip install matplotlib
Importing pyplot¶
- from matplotlib import pyplot as plt
or - import matplotlib.pyplot as plt
import matplotlib
print(matplotlib.__version__)
Available Style¶
import matplotlib.pyplot as plt
plt.style.available
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 |
Machine Learning Tutorials, Courses and Certifications