Home > other >  Plotting multiple graphs from equations in array in Python
Plotting multiple graphs from equations in array in Python

Time:05-04

I would like to plot each column vector of A as a function of x. Basically, the output should be 6 graphs here.

import numpy as np
from matplotlib import pyplot as plt
from sympy import Symbol
x=Symbol('x')

A=np.array([[1 - 0.0909090909090909*x**2],
       [1 - 0.166666666666667*x**2],
       [1 - 0.230769230769231*x**2],
       [1 - 0.285714285714286*x**2],
       [1 - 0.333333333333333*x**2],
       [1 - 0.375*x**2]])

x = np.linspace(0, 1, 100)
plt.plot(x, A, color='red')

CodePudding user response:

Calculate the matrix A after the assignment of the variable x, change the codes to this:

import numpy as np
from matplotlib import pyplot as plt
# from sympy import Symbol
# x=Symbol('x')

x = np.linspace(0, 1, 100)
A=np.r_[[1 - 0.0909090909090909*x**2],
       [1 - 0.166666666666667*x**2],
       [1 - 0.230769230769231*x**2],
       [1 - 0.285714285714286*x**2],
       [1 - 0.333333333333333*x**2],
       [1 - 0.375*x**2]]
plt.plot(x, A.T, color='red')
  • Related