1

I have the following:

Code:

 import math
 import matplotlib.pyplot as plt
 import numpy as np

 fn = np.tan

 x = np.linspace(-2*np.pi, 2*np.pi, 1000)
 points = [i * np.pi/2 for i in range(-4, 5)]
 labels = ["-2π", "-3π/2", "-π", "-π/2", "0", "π/2", "π", "3π/2", "2π"]

 fig, ax  = plt.subplots()
 ax.plot(x, fn(x))
 ax.set_xticks(points)
 ax.set_xticklabels(labels)

 for pt in points:
     ax.plot(pt, fn(pt), "ok")

 ax.hlines(0, x[0], x[-1], "k")
 ax.vlines(0, -1, 1, "k")

 plt.show()

I'd like to take my existing code, and (preferably) using matplotlib, plot two periods of my given trig function, and line up a couple of points on the graph with a couple of points on my function.

Gabriela
  • 111
  • 3

0 Answers0