plato-div-line.html
001| """Plato's Divided Line Analysis."""
002|
003| from sys import argv
004| from os import path
005| from mlchart import mlchart
006| from goodies import intervals
007|
008| BasePath = r'C:\CJS\prj\Python\blog'
009| ImgsPath = path.join(BasePath,'img')
010|
011|
012| class mlchart_plato_div_line (mlchart):
013| """Plato's Divided Line Analysis."""
014| def __init__ (self, p, q, start=1.0, stop=12.0, steps=1.0):
015| """New instance requires ratio P/Q (control info optional)."""
016| super().__init__()
017| self.dims = (5.0, 5.0)
018| self.margins = dict(left=0.150, right=0.980, bottom=0.14, top=0.93)
019| self.title = 'Plato\'s Divided Line'
020| self.x_title = 'Total Line Size'
021| self.y_title = 'Line/Segment Height'
022| self.x_limit = (0.0, +10.0)
023| self.y_limit = (0.0, +50.0)
024| self.x_grids = ( 5.0, 1.0)
025| self.y_grids = (10.0, 2.0)
026| self.x_tickf = '%.2f'
027| self.y_tickf = '%.2f'
028| self.fpath = ImgsPath
029| self.fname = 'platos-div-line.png'
030| self.p = p
031| self.q = q
032| self.u = q - p
033| self.fp = float(p)
034| self.fq = float(q)
035| self.d = self.fq / self.fp
036| self.scale = self.d - 1.0
037| self.start = start
038| self.stop = stop
039| self.steps = steps
040| print('upper: %d/%d (%.3f)' % (self.u,self.q, self.u/self.fq))
041| print('lower: %d/%d (%.3f)' % (self.p,self.q, self.fp/self.fq))
042| print('ratio: [1:d] d=%.3f' % self.d)
043| print('scale: %.3f' % self.scale)
044| print()
045|
046| def plotter (self):
047| """Plot something!"""
048| xs = []
049| ys1 = []
050| ys2 = []
051| ys3 = []
052| ys4 = []
053| for ix in intervals(self.start, self.stop, self.steps):
054| seg1 = ix
055| seg2 = ((ix * self.d) - ix)
056| seg3 = seg2
057| seg4 = (self.scale * seg2)
058| xs.append(ix)
059| ys1.append(seg1)
060| ys2.append(seg2)
061| ys3.append(seg4)
062| print()
063| pass
064| self.ax.plot(xs,ys1, c='#ff0000', lw=1.0, alpha=1.0, zorder=11)
065| self.ax.plot(xs,ys2, c='#00cc00', lw=1.0, alpha=1.0, zorder=12)
066| self.ax.plot(xs,ys3, c='#0000ff', lw=1.0, alpha=1.0, zorder=13)
067|
068|
069| def make_x_axis_spcl (self):
070| """Rotate X-axis labels 90 degrees."""
071| for tick in self.ax.xaxis.get_major_ticks():
072| tick.label1.set_rotation('vertical')
073| tick.label1.set_size(9)
074|
075|
076| def main ():
077| cht = mlchart_plato_div_line(1, 3)
078| cht.make()
079| print('wrote: %s' % path.join(cht.fpath, cht.fname))
080| print()
081|
082|
083| if __name__ == '__main__':
084| print(argv[0])
085| print()
086| main()
087| print()
088|
089| '''eof'''
090|