ml_three-phase.html


001| """Three-Phase (as in electrical) Chart."""
002| ####################################################################################################
003| from sys import argv
004| from os import path
005| from vector import vector
006| from mlchart import mlchart
007| ####################################################################################################
008| BasePath = r'C:\CJS\prj\Python\charts'
009| ImgsPath = path.join(BasePath,'img')
010| 
011| ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
012| class mlchart_three_phase (mlchart):
013|     """Three-Phase (as in electrical) Chart."""
014|     def __init__ (self):
015|         """New instance."""
016|         super().__init__()
017|         self.dims = (6.0, 4.0)
018|         self.margins = dict(left=0.100, right=0.975, bottom=0.12, top=0.93)
019|         self.title = '3-Phase Dot Products'
020|         self.x_title = 'Degrees'
021|         self.y_title = 'cos(a)'
022|         self.x_limit = (0.0, +360.0)
023|         self.y_limit = (-1.1, +1.1)
024|         self.x_grids = (90.0, 30.0)
025|         self.y_grids = (0.5, 0.1)
026|         self.x_tickf = '%d'
027|         self.y_tickf = '%.1f'
028|         self.fpath = ImgsPath
029|         self.fname = 'three-phase.png'
030| 
031|     def plotter (self):
032|         """Plot something!"""
033|         d1 = vector.frompolar(1.0, 0.0)
034|         d2 = vector.frompolar(1.0, 120.0)
035|         d3 = vector.frompolar(1.0, 240.0)
036| 
037|         xs = list(range(360))
038|         vs = [vector.frompolar(1.0, a) for a in xs]
039|         ys1 = [v.dot(d1) for v in vs]
040|         ys2 = [v.dot(d2) for v in vs]
041|         ys3 = [v.dot(d3) for v in vs]
042| 
043|         p1 = self.ax.plot(xs,ys1, c='#ff0000', lw=2.0, alpha=1.0, zorder=11)
044|         p2 = self.ax.plot(xs,ys2, c='#007f00', lw=2.0, alpha=1.0, zorder=12)
045|         p3 = self.ax.plot(xs,ys3, c='#0000ff', lw=2.0, alpha=1.0, zorder=13)
046|         self.ax.legend([p1[0],p2[0],p3[0]],['D(0)','D(120)', 'D(240)'], loc='lower right', shadow=True)
047| 
048|     def _make_x_axis_spcl (self):
049|         """Rotate X-axis labels 90 degrees."""
050|         for tick in self.ax.xaxis.get_major_ticks():
051|             tick.label1.set_rotation('vertical')
052|             tick.label1.set_size(9)
053| 
054| 
055| ##================================================================================================##
056| def main ():
057|     cht = mlchart_three_phase()
058|     cht.make()
059|     print('wrote: %s' % path.join(cht.fpath, cht.fname))
060|     print()
061| 
062| ####################################################################################################
063| if __name__ == '__main__':
064|     print(argv[0])
065|     print()
066|     main()
067|     print()
068| ####################################################################################################
069| '''eof'''
070|