z_math.html
001|
002| from os import path
003| import numpy as np
004| import matplotlib.pyplot as plt
005| from matplotlib.ticker import MultipleLocator, FormatStrFormatter
006|
007| BasePath = r'C:\CJS\prj\Python\charts'
008| ImgsPath = path.join(BasePath,'img')
009|
010|
011|
012| def do_chart_math ():
013| filename = path.join(ImgsPath,'z_math.png')
014|
015|
016| xmin = -5.0
017| xmax = +5.0
018| ymin = -5.00
019| ymax = +30.00
020| xt = np.linspace(xmin, xmax, 101)
021| dx1 = [x**2 for x in xt]
022| dx2 = [(x**2)+4 for x in xt]
023| dx3 = [(x**2)-4 for x in xt]
024|
025|
026| fig, ax = plt.subplots()
027| fig.suptitle('Parabolic Curves')
028| ax.set_xlabel('X Axis')
029| ax.set_ylabel('Y Axis')
030| ax.set_xlim(xmin, xmax)
031| ax.set_ylim(ymin, ymax)
032|
033| ax.minorticks_on()
034| ax.xaxis.set_major_locator(MultipleLocator(1.00))
035| ax.yaxis.set_major_locator(MultipleLocator(5.00))
036| ax.xaxis.set_minor_locator(MultipleLocator(0.25))
037| ax.yaxis.set_minor_locator(MultipleLocator(1.00))
038|
039| ax.xaxis.set_major_formatter(FormatStrFormatter('%+2d'))
040| ax.yaxis.set_major_formatter(FormatStrFormatter('%+3d'))
041|
042| ax.tick_params(which='major', axis='both', direction='out')
043| ax.tick_params(which='minor', axis='both', direction='out')
044|
045| ax.grid(which='major', axis='both', color='#7f7fbf', lw=1.0,ls='-', alpha=1.0, zorder=1)
046| ax.grid(which='minor', axis='both', color='#bfbfff', lw=0.5,ls='-', alpha=1.0, zorder=0)
047|
048| ax.axhline(0.0, lw=2.00, color='k', zorder=2)
049| ax.axvline(0.0, lw=2.00, color='k', zorder=2)
050| ax.plot(xt,dx2, color='#0000ff', label='$x^2+4$', lw=3.00, alpha=1.00, zorder=7)
051| ax.plot(xt,dx1, color='#007f00', label='$x^2$' , lw=3.00, alpha=1.00, zorder=9)
052| ax.plot(xt,dx3, color='#ff0000', label='$x^2-4$', lw=3.00, alpha=1.00, zorder=8)
053| ax.legend(loc='upper center', bbox_to_anchor=(0.666,1.0), shadow=True)
054|
055| fig.set_figwidth(4.0)
056| fig.set_figheight(4.0)
057| fig.subplots_adjust(left=0.17, bottom=0.15, right=0.97, top=0.92)
058| fig.savefig(filename)
059|
060|
061|
062|
063| if __name__ == '__main__':
064| do_chart_math()
065|
066| '''eof'''
067|