python - Graphing tan in matplotlib -


i have following code:

from mpl_toolkits.axes_grid.axislines import subplotzero matplotlib.transforms import blendedgenerictransform import matplotlib.pyplot plt import numpy  if 1:     fig = plt.figure(1)     ax = subplotzero(fig, 111)     fig.add_subplot(ax)      ax.axhline(linewidth=1.7, color="black")     ax.axvline(linewidth=1.7, color="black")      plt.xticks([1])     plt.yticks([])      ax.text(0, 1.05, 'y', transform=blendedgenerictransform(ax.transdata, ax.transaxes), ha='center')     ax.text(1.05, 0, 'x', transform=blendedgenerictransform(ax.transaxes, ax.transdata), va='center')      direction in ["xzero", "yzero"]:         ax.axis[direction].set_axisline_style("-|>")         ax.axis[direction].set_visible(true)      direction in ["left", "right", "bottom", "top"]:         ax.axis[direction].set_visible(false)      x = numpy.linspace(-1, 1, 10000)     ax.plot(x, numpy.tan(2*(x - numpy.pi/2)), linewidth=1.2, color="black")      plt.ylim(-5, 5)     plt.savefig('graph.png') 

which produces graph: graph

as can see, not tan graph sketched, portion of line added join asymptotic regions of tan graph, asymptote be.

is there built in way skip section? or graph separate disjoint domains of tan bounded asymptotes (if mean)?

something try: set finite threshold , modify function provide non-finite values after points. practical code modification:

yy = numpy.tan(2*(x - numpy.pi/2)) threshold = 10000 yy[yy>threshold] = numpy.inf yy[yy<-threshold] = numpy.inf ax.plot(x, yy, linewidth=1.2, color="black") 

results in:

result


Comments