|
| 1 | +import numpy as np |
| 2 | +import numpy.polynomial.polynomial as P |
| 3 | + |
| 4 | +from pyx import color, deco, graph, style |
| 5 | + |
| 6 | +np.random.seed(987) |
| 7 | +x = np.pi*np.linspace(0, 1, 100) |
| 8 | +y = np.sin(x)+0.1*np.random.rand(100) |
| 9 | +fit = P.Polynomial(P.polyfit(x, y, 2)) |
| 10 | + |
| 11 | +g = graph.graphxy(width=8, |
| 12 | + x=graph.axis.lin(title=r'\Large $x$', divisor=np.pi, |
| 13 | + texter=graph.axis.texter.rational(suffix=r'\pi')), |
| 14 | + y=graph.axis.lin(min=0, max=1.1, title=r'\Large $y$', |
| 15 | + parter=graph.axis.parter.lin(tickdists=[0.2]))) |
| 16 | +origdata = list(zip(x, y)) |
| 17 | +symbolattrs = [deco.filled, color.hsb(0.6, 1, 0.7)] |
| 18 | +g.plot(graph.data.points(origdata, x=1, y=2), |
| 19 | + [graph.style.symbol(graph.style.symbol.circle, 0.07, |
| 20 | + symbolattrs=symbolattrs)]) |
| 21 | +fitdata = list(zip(x, fit(x))) |
| 22 | +lineattrs = [color.hsb(0.05, 1, 0.7), style.linewidth.THick] |
| 23 | +g.plot(graph.data.points(fitdata, x=1, y=2), |
| 24 | + [graph.style.line(lineattrs=lineattrs)]) |
| 25 | +g.writePDFfile() |
0 commit comments