I've got a function of one variable (r) and two constants (R and γ). I would like to make 9 different plots for each combination of the two constants being equal to three values each.
Here's what I've come up with so far:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
plt.rc('font', size=14)
fig, axs = plt.subplots(3, 3, figsize=(15,15))
# Defining function
def f(r, R, γ):
if r <= R:
return 1+γ*(r/R)**(γ+1) - (γ+1)*(r/R)**γ
else:
return 0
r = np.linspace(0, 10, 100)
γs = [1, 2, 3]
Rs = [2, 4, 6]
for i in range(9):
for γ in range(3):
for R in range(3):
axs[i].plot(r, f(r, Rs[R], γs[γ]))
However, I get this error code:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-faa7cd86fd6b> in <module>
19 for γ in range(3):
20 for R in range(3):
---> 21 axs[i].plot(r, f(r, Rs[R], γs[γ]))
AttributeError: 'numpy.ndarray' object has no attribute 'plot'
How do I make python display 9 plots with f(r, 2, 1), f(r, 4, 1), f(r, 6, 1), f(r, 2, 2), ...?

