mbrot-calcs.html
001| '''Mandelbrot Calculations Chart.'''
002|
003| from os import path
004| from math import sqrt
005| import matplotlib.pyplot as plt
006| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
007| from files import linefile
008|
009| BasePath = r'C:\CJS\prj\Python\ws\math'
010| DataPath = path.join(BasePath, 'out')
011| ImgsPath = path.join(BasePath, 'img')
012| Filename = 'mbrot-calcs.png'
013| RealData = 'mbrot-r.out'
014| ImagData = 'mbrot-i.out'
015| Coords = '-0.75 x +0.000001'
016| MagYAxis = 10000.0
017|
018| Skip = 1
019|
020|
021|
022| def main (*args):
023|
024| fr = linefile(path.join(DataPath, RealData))
025| fr.load()
026|
027| yrs = []
028| for ix,s in enumerate(fr):
029| if (ix % Skip) == 0:
030| yrs.append(float(s))
031| xrs = [x+1 for x in range(len(yrs))]
032|
033| fi = linefile(path.join(DataPath, ImagData))
034| fi.load()
035| yis = []
036| for ix,s in enumerate(fi):
037| if (ix % Skip) == 0:
038| yis.append(MagYAxis* float(s))
039| xis = [x+1 for x in range(len(yis))]
040|
041| XMax = ((len(xrs)+10)//10)*10
042| XMaj = (XMax//1000)*100
043| XMin = XMaj // 10
044| print(XMax, XMaj, XMin)
045|
046| fig, ax = plt.subplots()
047| fig.suptitle('Mandelbrot Calculations [%s]' % Coords)
048|
049| ax.set_xlabel('Iterations')
050| ax.set_xlim(0, XMax)
051| ax.xaxis.set_major_locator(MultipleLocator(XMaj))
052| ax.xaxis.set_minor_locator(MultipleLocator(XMin))
053| ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
054|
055| for tick in ax.xaxis.get_major_ticks():
056| tick.label1.set_rotation('vertical')
057| tick.label1.set_size(9)
058|
059| ax.set_ylabel('Orbits')
060| ax.set_ylim(-1.5, +1.5)
061| ax.yaxis.set_major_locator(MultipleLocator(0.5))
062| ax.yaxis.set_minor_locator(MultipleLocator(0.1))
063| ax.yaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
064|
065| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
066| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
067| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
068| ax.tick_params(which='minor', axis='both', direction='out', color='#000000')
069|
070| ax.plot(xrs,yrs, color='red', label='real', lw=1.0, alpha=0.8, zorder=11)
071| ax.plot(xis,yis, color='blue', label='imag', lw=1.0, alpha=0.8, zorder=10)
072| ax.legend(loc='upper left', bbox_to_anchor=(0.0,1.0), shadow=True)
073|
074| fig.set_figwidth(8.0)
075| fig.set_figheight(6.0)
076| fig.subplots_adjust(left=0.09, right=0.99, bottom=0.12, top=0.94)
077|
078| fn = path.join(ImgsPath, Filename)
079| fig.savefig(fn)
080|
081| return ()
082|
083|
084| if __name__ == '__main__':
085| print(argv[0])
086| print()
087| rv = main(*argv[1:])
088| print()
089|
090| '''eof'''
091|