#!/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_arccos_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.set_bordersize(fig, 53.5, 31.5, 18.5, 26.5)
fig.gca().yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.25))
fig.gca().xaxis.set_major_locator(mpl.ticker.MultipleLocator(0.5))
xlim = -1.25,1.25; fig.gca().set_xlim(xlim)
ylim = -0.06, 1.06; fig.gca().set_ylim(ylim)
mplwp.mark_axeszero(fig.gca())
f = lambda y: cos(pi*y)
y = np.linspace(0, 1, 5001)
x = [f(yy) for yy in y]
plt.plot(x, y, label='arccos')
plt.plot([-1,1],[1,0], '.', color=fig.gca().lines[-1].get_color())
plt.legend(loc='upper center').get_frame().set_alpha(0.9)
plt.savefig(name)
mplwp.postprocess(name)