ml_great-conjunctions.html
001| """Great Conjunctions Chart."""
002|
003| from sys import argv
004| from os import path
005| from datetime import date
006| from matplotlib.ticker import NullFormatter
007| from matplotlib.dates import YearLocator, DateFormatter
008| from files import csvfile
009| from mlchart import mlchart
010|
011| BasePath = r'C:\CJS\prj\Python\charts'
012| ImgsPath = path.join(BasePath,'img')
013| DatFilename = 'great-conjunctions.csv'
014| ImgFilename = 'great-conjunctions.png'
015|
016|
017| class great_conjunctions (mlchart):
018| """Great Conjunctions Chart Class."""
019| def __init__ (self, xs, ys):
020| """New instance requires data."""
021| super().__init__()
022| self.xs = xs
023| self.ys = ys
024| self.dims = (8.0, 4.0)
025| self.margins = dict(left=0.11, right=0.99, bottom=0.12, top=0.93)
026| self.title = 'Great Conjunctions'
027| self.x_title = ''
028| self.y_title = 'Angular Separation'
029| self.x_limit = (date(1200,1,1), date(2400,1,1))
030| self.y_limit = (0.0, +80.0)
031| self.x_grids = (1.0, 0.10)
032| self.y_grids = (10.0, 2.50)
033| self.x_tickf = '%+.1f'
034| self.y_tickf = '%+.1f'
035| self.fpath = BasePath
036| self.fname = ImgFilename
037|
038| def plotter (self):
039| """Plot something!"""
040| self.ax.plot(self.xs,self.ys, color='#3366bf', lw=0.8, marker='o',ms=5,mfc='#ff0000',mew=0, alpha=0.75, zorder=10)
041|
042|
043| def make_x_axis_spcl (self):
044| """Special handling for X-axis."""
045|
046| self.ax.xaxis.set_major_locator(YearLocator(500))
047| self.ax.xaxis.set_minor_locator(YearLocator(100))
048| self.ax.xaxis.set_major_formatter(NullFormatter())
049| self.ax.xaxis.set_minor_formatter(DateFormatter('%Y'))
050|
051| for tick in self.ax.xaxis.get_minor_ticks():
052| tick.label1.set_rotation('vertical')
053| tick.label1.set_size(9)
054|
055|
056| def main ():
057| fn = path.join(BasePath, DatFilename)
058| fo = csvfile(fn)
059| fo.load()
060|
061| data = [(int(row[0].split()[2]), float(row[1])) for row in fo]
062|
063| xs = [date(d[0],1,1) for d in data]
064| ys = [float(d[1]) for d in data]
065|
066| cht = great_conjunctions(xs, ys)
067| cht.make()
068| print('wrote: %s' % path.join(cht.fpath, cht.fname))
069| print()
070|
071|
072| if __name__ == '__main__':
073| print(argv[0])
074| print()
075| main()
076| print()
077|
078| '''eof'''
079|