#!/usr/bin/python # -*- coding: utf8 -*- import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np from math import * code_website = 'http://commons.wikimedia.org/wiki/User:Geek3/mplwp' try: import mplwp except ImportError, er: print 'ImportError:', er print 'You need to download mplwp.py from', code_website exit(1) name = 'mplwp_inverse_trigonometric_functions_piaxis.svg' fig = mplwp.fig_standard(mpl) # add pi to xaxis labels def flabel(x, i): return u'{}\u03C0'.format(x).replace('-', u'\u2212') fig.gca().yaxis.set_major_formatter(mpl.ticker.FuncFormatter(flabel)) # make space for labels mplwp.move_axes(fig, 21, 0) fig.gca().yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.25)) xlim = -4,4; fig.gca().set_xlim(xlim) ylim = -0.625, 1.125; fig.gca().set_ylim(ylim) mplwp.mark_axeszero(fig.gca()) y1 = np.linspace(-0.5, 0.5, 5001) x1 = [sin(pi*yy) for yy in y1] plt.plot(x1, y1, label='arcsin') plt.plot([-1,1], [-0.5,0.5], '.', color=fig.gca().lines[-1].get_color()) y2 = np.linspace(0, 1, 5001) x2 = [cos(pi*yy) for yy in y2] plt.plot(x2, y2, label='arccos') plt.plot([1,-1], [0,1], '.', color=fig.gca().lines[-1].get_color()) x3 = np.linspace(xlim[0], xlim[1], 5001) y3 = [atan(xx)/pi for xx in x3] plt.plot(x3, y3, label='arctan') x4 = np.linspace(xlim[0], xlim[1], 5001) y4 = [0.5 - atan(xx)/pi for xx in x4] plt.plot(x4, y4, label='arccot') def sec(y): a = cos(pi*y) if fabs(a) < 0.1: return float('NaN') return 1.0 / a y5 = np.linspace(0, 1, 5001) x5 = [sec(yy) for yy in y5] plt.plot(x5, y5, label='arcsec') plt.plot([1,-1], [0,1], '.', color=fig.gca().lines[-1].get_color()) def csc(y): a = sin(pi*y) if fabs(a) < 0.1: return float('NaN') return 1.0 / a y6 = np.linspace(-0.5, 0.5, 5001) x6 = [csc(yy) for yy in y6] plt.plot(x6, y6, label='arccsc') plt.plot([-1,1], [-0.5,0.5], '.', color=fig.gca().lines[-1].get_color()) mpl.rc('legend', borderaxespad=0.8) plt.legend(loc='upper right', ncol=2, columnspacing=1.2, handletextpad=0.4).get_frame().set_alpha(0.9) plt.savefig(name) mplwp.postprocess(name)