@sines-4.py
from __future__ import print_function
from os import path
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
ImgsPath = r'C:\CJS\prj\Python\ws\charts\imgs'
fn = 'sines-4.png'
Radians = lambda d: 2.0 * np.pi * (d/360.0)
xmin,xmax = (-12.0 * np.pi), (+12.0 * np.pi)
ymax,ymin = +2.00, -2.00
xt = np.arange(xmin, xmax, 0.01)
dxs = []
for ix in range(10):
n = 1+(1.9*ix)
dx = [np.sin(x*n) / float(n) for x in xt]
dxs.append(dx)
dx0 = [sum(d) for d in zip(*dxs)]
fig, ax = plt.subplots()
fig.suptitle('Sine Waves')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
ax.minorticks_on()
ax.xaxis.set_major_locator(MultipleLocator(np.pi * 2))
ax.yaxis.set_major_locator(MultipleLocator(0.25))
ax.xaxis.set_major_formatter(FormatStrFormatter('%.2f'))
ax.yaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
ax.xaxis.set_minor_locator(MultipleLocator(np.pi/4))
ax.yaxis.set_minor_locator(MultipleLocator(0.05))
ax.tick_params(which='major', axis='both', direction='out', zorder=0)
ax.tick_params(which='minor', axis='both', direction='out', zorder=0)
ax.grid(which='minor', axis='both', color='#efefff', lw=0.6,ls='-',zorder=0, alpha=1.0)
ax.grid(which='major', axis='both', color='#7f7fbf', lw=1.2,ls='-',zorder=1, alpha=1.0)
for ix,dx in enumerate(dxs):
c = (float(ix+1) / 10.0)
ax.plot(xt,dx, color=(c,c,c), lw=0.80, zorder=3, alpha=0.85)
ax.plot(xt,dx0, color='#ff0000', lw=1.60, zorder=9, alpha=0.85)
fig.set_figwidth(8.0)
fig.set_figheight(4.8)
fig.subplots_adjust(left=0.10, bottom=0.10, right=0.90, top=0.90)
fig.savefig(path.join(ImgsPath,fn))
plt.show()