How To Plot Numpy Arrays?

Table Of Contents:

  1. Using ‘matplotlib’ Library To Plot The Numpy.
  2. Examples Of Plotting.

Example-1

import matplotlib.pyplot as plt
%matplotlib inline

a = np.array([2, 1, 5, 7, 4, 6, 8, 14, 10, 9, 18, 20, 22])
plt.plot(a)

Example-2

import matplotlib.pyplot as plt
%matplotlib inline

x = np.linspace(0, 5, 20)
y = np.linspace(0, 10, 20)
plt.plot(x, y, 'purple') # line
plt.plot(x, y, 'o')      # dots

Example-3

import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
X = np.arange(-5, 5, 0.15)
Y = np.arange(-5, 5, 0.15)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='viridis')

Leave a Reply

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