|
1 | | -# make plots using the root finding methods in roots.py |
2 | | -# |
3 | | -# M. Zingale (2013-02-14) |
| 1 | +""" |
| 2 | +make plots using the root finding methods in roots.py |
| 3 | +
|
| 4 | +M. Zingale (2013-02-14) |
| 5 | +""" |
4 | 6 |
|
5 | 7 | from __future__ import print_function |
6 | 8 |
|
7 | | -import math |
8 | 9 | import numpy |
9 | 10 | import matplotlib as mpl |
10 | 11 | import matplotlib.pyplot as plt |
11 | | -from roots import * |
| 12 | +import roots |
12 | 13 | from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset |
13 | 14 |
|
14 | 15 | mpl.rcParams['xtick.labelsize'] = 16 |
15 | 16 | mpl.rcParams['ytick.labelsize'] = 16 |
16 | 17 | mpl.rcParams['mathtext.fontset'] = 'cm' |
17 | 18 | mpl.rcParams['mathtext.rm'] = 'serif' |
18 | 19 |
|
19 | | -r = root(f, 1.e-5, fprime=fprime) |
| 20 | +r = roots.Root(roots.f, 1.e-5, fprime=roots.fprime) |
20 | 21 |
|
21 | 22 | xmin = 0.0 |
22 | 23 | xmax = 5.0 |
|
35 | 36 | plt.plot(xfine, r.f(xfine)) |
36 | 37 |
|
37 | 38 | plt.scatter(numpy.array(xeval[0:n+1]), |
38 | | - r.f(numpy.array(xeval[0:n+1])), |
39 | | - marker="x", s=25, color="r", zorder=100) |
| 39 | + r.f(numpy.array(xeval[0:n+1])), |
| 40 | + marker="x", s=25, color="r", zorder=100) |
40 | 41 |
|
41 | 42 | plt.plot(xfine, r.fprime(x)*(xfine-x) + r.f(x), color="0.5") |
42 | 43 |
|
|
45 | 46 | plt.plot([xintercept, xintercept], [0, r.f(xintercept)], color="0.5", ls=":") |
46 | 47 |
|
47 | 48 | if n%2 == 0: |
48 | | - plt.text(x, r.f(x)-0.3, "{}".format(n), |
| 49 | + plt.text(x, r.f(x)-0.3, "{}".format(n), |
49 | 50 | color="r", fontsize="16", |
50 | 51 | verticalalignment="top", horizontalalignment="center", zorder=1000) |
51 | 52 | else: |
52 | | - plt.text(x, r.f(x)+0.3, "{}".format(n), |
| 53 | + plt.text(x, r.f(x)+0.3, "{}".format(n), |
53 | 54 | color="r", fontsize="16", |
54 | 55 | verticalalignment="bottom", horizontalalignment="center", zorder=1000) |
55 | 56 |
|
56 | 57 | F = plt.gcf() |
57 | | - plt.text(0.4, 0.02, "root approx = {}".format(x), |
| 58 | + plt.text(0.4, 0.02, "root approx = {}".format(x), |
58 | 59 | transform = F.transFigure, color="k", fontsize="16") |
59 | 60 |
|
60 | 61 | # axes through origin |
|
94 | 95 | axins.plot([xintercept, xintercept], [0, r.f(xintercept)], color="0.5", ls=":") |
95 | 96 |
|
96 | 97 | if n%2 == 0: |
97 | | - axins.text(x, r.f(x)-0.05, "{}".format(n), |
| 98 | + axins.text(x, r.f(x)-0.05, "{}".format(n), |
98 | 99 | color="r", fontsize="10", |
99 | 100 | verticalalignment="top", horizontalalignment="center", |
100 | 101 | clip_on=True, zorder=100) |
101 | 102 | else: |
102 | | - axins.text(x, r.f(x)+0.05, "{}".format(n), |
| 103 | + axins.text(x, r.f(x)+0.05, "{}".format(n), |
103 | 104 | color="r", fontsize="10", |
104 | 105 | verticalalignment="bottom", horizontalalignment="center", |
105 | 106 | clip_on=True, zorder=100) |
|
0 commit comments