ml_gamma.html


001| """Gamma Charts (three)."""
002| ####################################################################################################
003| from sys import argv
004| from os import path
005| from math import sqrt
006| from mlchart import mlchart
007| ####################################################################################################
008| BasePath = r'C:\CJS\prj\Python\charts'
009| ImgsPath = path.join(BasePath,'img')
010| Filename1 = 'gamma-1.png'
011| Filename2 = 'gamma-2.png'
012| Filename3 = 'gamma-3.png'
013| 
014| gamma = lambda v: (1.0 / sqrt(1.0 - ((v*v)/1.0)))
015| 
016| ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
017| class gamma_chart (mlchart):
018|     """Gamma Chart Class."""
019|     def __init__ (self):
020|         """New instance."""
021|         super().__init__()
022|         self.dims = (8.0, 6.0)
023|         self.margins = dict(left=0.09, right=0.98, bottom=0.11, top=0.94)
024|         self.title = 'Gamma Factor'
025|         self.x_title = 'Fraction of C'
026|         self.y_title = 'Gamma Factor'
027|         self.title_kw['fontsize'] = 16
028|         self.x_title_kw['fontsize'] = 12
029|         self.y_title_kw['fontsize'] = 12
030|         self.x_limit = (0.0, 1.0)
031|         self.y_limit = (0.0, +10.0)
032|         self.x_grids = (0.10, 0.025)
033|         self.y_grids = (1.00, 0.25)
034|         self.x_tickf = '%.1f'
035|         self.y_tickf = '%.1f'
036|         self.fpath = BasePath
037|         self.fname = 'gamma.png'
038|         self.xs = []
039|         self.ys = []
040| 
041|     def plotter (self):
042|         """Plot something!"""
043|         self.ax.axvline(c='#000000', lw=2.0, alpha=1.00, zorder=11)
044|         self.ax.axhline(c='#000000', lw=2.0, alpha=1.00, zorder=12)
045|         self.ax.plot(self.xs,self.ys, label='gamma', color='#ff0000', lw=2.0, ms=0, alpha=1.0, zorder=9)
046| 
047|     def make_x_axis_spcl (self):
048|         """Rotate X-axis labels 90 degrees."""
049|         for tick in self.ax.xaxis.get_major_ticks():
050|             tick.label1.set_rotation('vertical')
051|             tick.label1.set_size(9)
052| 
053| ##================================================================================================##
054| def gamma_1 ():
055|     """Create chart of gamma from v=[0.0c, 1.0c]."""
056|     class gamma_chart_1 (gamma_chart):
057|         def __init__ (self):
058|             super().__init__()
059|             self.title = 'Gamma Factor 0.0c - 1.0c'
060|             self.fname = Filename1
061|             self.xs = [(float(x)/1000.0) for x in range(0, 1000, 5)]
062|             self.ys = [gamma(x) for x in self.xs]
063| 
064|     cht = gamma_chart_1()
065|     cht.make()
066|     print('wrote: %s' % path.join(cht.fpath, cht.fname))
067|     print()
068| 
069| ##================================================================================================##
070| def gamma_2 ():
071|     """Create chart of gamma from v=[0.9c, c]."""
072|     class gamma_chart_2 (gamma_chart):
073|         def __init__ (self):
074|             super().__init__()
075|             self.title = 'Gamma Factor 0.9c - 1.0c'
076|             self.fname = Filename2
077|             self.x_limit = (0.9, 1.0)
078|             self.y_limit = (0.0, +40.0)
079|             self.x_grids = (0.01, 0.0025)
080|             self.y_grids = (5.00, 1.00)
081|             self.x_tickf = '%.2f'
082|             self.xs = [((2700.0+float(x))/3000.0) for x in range(300)]
083|             self.ys = [gamma(x) for x in self.xs]
084| 
085|     cht = gamma_chart_2()
086|     cht.make()
087|     print('wrote: %s' % path.join(cht.fpath, cht.fname))
088|     print()
089| 
090| ##================================================================================================##
091| def gamma_3 ():
092|     """Create chart of gamma from v=[0.999c, c]."""
093|     class gamma_chart_3 (gamma_chart):
094|         def __init__ (self):
095|             super().__init__()
096|             self.margins = dict(left=0.10, right=0.98, bottom=0.14, top=0.94)
097|             self.title = 'Gamma Factor 0.999c - 1.0c'
098|             self.fname = Filename3
099|             self.x_limit = (0.999, 1.0)
100|             self.y_limit = (0.0, +300.0)
101|             self.x_grids = (0.0001, 0.000025)
102|             self.y_grids = (25.00, 5.00)
103|             self.x_tickf = '%.4f'
104|             self.xs = [((199800.0+float(x))/200000.0) for x in range(200)]
105|             self.ys = [gamma(x) for x in self.xs]
106| 
107|     cht = gamma_chart_3()
108|     cht.make()
109|     print('wrote: %s' % path.join(cht.fpath, cht.fname))
110|     print()
111| 
112| 
113| ##================================================================================================##
114| def main ():
115|     #gamma_1()
116|     #gamma_2()
117|     gamma_3()
118|     print()
119| 
120| ####################################################################################################
121| if __name__ == '__main__':
122|     print(argv[0])
123|     print()
124|     main()
125|     print()
126| ####################################################################################################
127| '''eof'''
128|