- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot 2D math vectors with Matplotlib?
To plot 2D math vectors with matplotlib, we can take the following steps−
- Create vector cordinates using numpy array.
- Get x, y, u and v data points.
- Create a new figure or activate an existing figure using figure method.
- Get the current axis using gca() method.
- Set x an y limits of the axes.
- To redraw the current figure, use draw() method.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True soa = np.array([[0, 0, 3, 2], [0, 0, 4, 5], [0, 0, 9, 9]]) X, Y, U, V = zip(*soa) plt.figure() ax = plt.gca() ax.quiver(X, Y, U, V, angles='xy', scale_units='xy', scale=1, color=['red', 'green', 'yellow']) ax.set_xlim([-1, 10]) ax.set_ylim([-1, 10]) plt.draw() plt.show()
Output
- Related Articles
- How to plot vectors in Python using Matplotlib?
- How to plot a 2D matrix in Python with colorbar Matplotlib?
- How to plot a 2D histogram in Matplotlib?
- How to plot 2d FEM results using matplotlib?
- How to plot a smooth 2D color plot for z = f(x, y) in Matplotlib?
- How to visualize scalar 2D data with Matplotlib?
- Putting arrowheads on vectors in Matplotlib's 3D plot
- How to plot with xgboost.XGBCClassifier.feature_importances_ model? (Matplotlib)
- How to plot with different scales in Matplotlib?
- How to create a Swarm Plot with Matplotlib?
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot a smooth line with matplotlib?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to plot matplotlib contour?
- How to update the plot title with Matplotlib using animation?

Advertisements