Monday, June 20, 2022

Plotting 3D Vector Matplotlib Numpy Python

 Требования (3D)




















Если вы хотите построить векторы v1 и v2, начиная с начала координат, вы должны использовать:

soa = np.array([[0, 0, 0, 0, 2, 1], [0, 0, 0, 2, 2, 0]])

Код построения


import numpy as np

import matplotlib.pyplot as plt


fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

soa = np.array([[0, 0, 0, 0, 2, 1], [0, 0, 0, 2, 2, 0]])

X, Y, Z, U, V, W = zip(*soa)

ax.quiver(X, Y, Z, U, V, W)

ax.set_xlim([-1, 5])

ax.set_ylim([-1, 5])

ax.set_zlim([-1, 8])

ax.set_xlabel('x')

ax.set_ylabel('y')

ax.set_zlabel('z')

plt.show()

















soa = np.array([[0, 0, 0, 0, 3, 5], [0, 0, 0, 2, 2, 3]])


















=================

2D Vector plot

=================

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()


















(.env) boris@boris-All-Series:~/VOTING$ cat Vector2D.py

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, 4, 5], [0, 0, 7, 6],[4, 5, 3, 1]])

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()



















No comments:

Post a Comment