In [1]:
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
----------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import pandas as pd 2 import matplotlib.pyplot as plt 3 from matplotlib.ticker import MaxNLocator ModuleNotFoundError: No module named 'pandas'
In [2]:
def fib_list(n: int) -> list[int]:
fibs = [0, 1]
for _ in range(2, n):
fibs.append(fibs[-1] + fibs[-2])
return fibs
In [4]:
def plot_fib(n: int) -> None:
fibs = fib_list(n)
df = pd.DataFrame({"n": list(range(1, n+1)), "fib": fibs})
# Plot inline
plt.figure(figsize=(10, 4))
plt.xlabel("n (index)")
plt.ylabel("Fib(n)")
plt.plot(df["n"], df["fib"], marker="o")
plt.xlabel("n (index)")
plt.ylabel("Fib(n)")
plt.title(f"First {n} Fibonacci numbers")
plt.grid(True)
ax = plt.gca()
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.yaxis.set_major_locator(MaxNLocator(integer=True))
plt.tight_layout()
plt.show()
In [5]:
n = 20
plot_fib(n)
----------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[5], line 2 1 n = 20 ----> 2 plot_fib(n) Cell In[4], line 3, in plot_fib(n) 1 def plot_fib(n: int) -> None: 2 fibs = fib_list(n) ----> 3 df = pd.DataFrame({"n": list(range(1, n+1)), "fib": fibs}) 5 # Plot inline 6 plt.figure(figsize=(10, 4)) NameError: name 'pd' is not defined
In [ ]: