- Matplotlib - Transforms
- Matplotlib - Working with Images
- Mathematical Expressions
- Matplotlib - Working With Text
- Matplotlib - 3D Surface plot
- Matplotlib - 3D Wireframe plot
- Matplotlib - 3D Contour Plot
- Three-dimensional Plotting
- Matplotlib - Violin Plot
- Matplotlib - Box Plot
- Matplotlib - Quiver Plot
- Matplotlib - Contour Plot
- Matplotlib - Scatter Plot
- Matplotlib - Pie Chart
- Matplotlib - Histogram
- Matplotlib - Bar Plot
- Matplotlib - Twin Axes
- Setting Ticks and Tick Labels
- Matplotlib - Setting Limits
- Matplotlib - Formatting Axes
- Matplotlib - Grids
- Matplotlib - Subplot2grid() Function
- Matplotlib - Subplots() Function
- Matplotlib - Multiplots
- Matplotlib - Axes Class
- Matplotlib - Figure Class
- Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Simple Plot
- Matplotlib - Pyplot API
- Matplotlib - Jupyter Notebook
- Matplotlib - Anaconda distribution
- Matplotlib - Environment Setup
- Matplotlib - Introduction
- Matplotlib - Home
Matplotlib Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Matplotpb - PyLab module
PyLab is a procedural interface to the Matplotpb object-oriented plotting pbrary. Matplotpb is the whole package; matplotpb.pyplot is a module in Matplotpb; and PyLab is a module that gets installed alongside Matplotpb.
PyLab is a convenience module that bulk imports matplotpb.pyplot (for plotting) and NumPy (for Mathematics and working with arrays) in a single name space. Although many examples use PyLab, it is no longer recommended.
Basic Plotting
Plotting curves is done with the plot command. It takes a pair of same-length arrays (or sequences) −
from numpy import * from pylab import * x = pnspace(-3, 3, 30) y = x**2 plot(x, y) show()
The above pne of code generates the following output −
To plot symbols rather than pnes, provide an additional string argument.
symbols | - , –, -., , . , , , o , ^ , v , < , > , s , + , x , D , d , 1 , 2 , 3 , 4 , h , H , p , | , _ |
colors | b, g, r, c, m, y, k, w |
Now, consider executing the following code −
from pylab import * x = pnspace(-3, 3, 30) y = x**2 plot(x, y, r. ) show()
It plots the red dots as shown below −
Plots can be overlaid. Just use the multiple plot commands. Use clf() to clear the plot.
from pylab import * plot(x, sin(x)) plot(x, cos(x), r- ) plot(x, -sin(x), g-- ) show()
The above pne of code generates the following output −
Advertisements