matter.html
001| """Contents of the Universe Pie Chart."""
002|
003| from sys import argv
004| from os import path
005| import matplotlib.pyplot as plt
006|
007| BasePath = r'C:\CJS\prj\Python\blog'
008| ImgsPath = path.join(BasePath,'img')
009| Filename = 'matter.png'
010|
011| clrs = ['#000000', '#000000', '#000000', '#000000', '#000000']
012| legendprops = {
013| 'ncol': 1,
014| 'fontsize': 9,
015| 'shadow': True,
016| 'facecolor': 'white',
017| 'framealpha': 1.0
018| }
019|
020|
021| def main ():
022| fig,axes = plt.subplots(nrows=1, ncols=2, squeeze=True)
023| fig.suptitle('Matter/Energy in the Universe', fontsize=18, fontweight='bold')
024| fig.set_figwidth(8.8)
025| fig.set_figheight(5.0)
026| fig.set_tight_layout({'pad':3.50})
027| fig.subplots_adjust(left=0.00, right=0.90, bottom=0.00, top=0.90)
028|
029| ax1 = axes[0]
030| ax2 = axes[1]
031| ax1.set_title('Total Energy Budget', fontsize=15, fontweight='bold')
032| ax2.set_title('Total Matter Budget', fontsize=15, fontweight='bold')
033|
034|
035| data1 = [68.3, 26.8, 5.0]
036| labs1 = ['Dark Energy', 'Dark Matter', 'Regular Matter']
037| cols1 = ['#3366cc', '#66cc33', '#cc3366']
038| expl1 = [0.0, 0.00, 0.00]
039| pie1props = {
040| 'labels': labs1,
041| 'colors': cols1,
042| 'explode': expl1,
043| 'startangle': 90,
044| 'counterclock': True,
045| 'shadow': True,
046| }
047| wdgs1,txts1 = ax1.pie(data1, **pie1props)
048|
049| for t in txts1:
050| txt = t.get_text()
051| x,y = t.get_position()
052| t.set_fontsize(12.0)
053| if txt == 'Dark Energy':
054| p = (x+1.15, y+0.25)
055| t.set_position(p)
056| t.set_fontsize(14.0)
057| t.set_fontweight('bold')
058| continue
059| if txt == 'Dark Matter':
060| p = (x-0.82, y-0.35)
061| t.set_position(p)
062| continue
063| if txt == 'Regular Matter':
064| p = (x-0.55, y)
065| t.set_position(p)
066| continue
067|
068| lbls1 = ['%s (%.2f%%)' % t for t in zip(labs1, data1)]
069| ax1.legend(wdgs1, lbls1, loc=(+0.25, -0.1333), **legendprops)
070|
071|
072| data2 = [84.28, 15.41, 0.31]
073| labs2 = ['Dark Matter', 'Regular Matter', 'Neutrinos']
074| cols2 = ['#66cc33', '#cc3366', '#000000']
075| expl2 = [0.0, 0.00, 0.00]
076| pie2props = {
077| 'labels': labs2,
078| 'colors': cols2,
079| 'explode': expl2,
080| 'startangle': 90,
081| 'counterclock': True,
082| 'shadow': True,
083| }
084| wdgs2,txts2 = ax2.pie(data2, **pie2props)
085|
086| for t in txts2:
087| txt = t.get_text()
088| x,y = t.get_position()
089| t.set_fontsize(12.0)
090| if txt == 'Dark Matter':
091| p = (x+0.75, y+0.60)
092| t.set_position(p)
093| t.set_fontsize(14.0)
094| t.set_fontweight('bold')
095| continue
096| if txt == 'Regular Matter':
097| p = (x-0.04, y-0.05)
098| t.set_position(p)
099| continue
100| if txt == 'Neutrinos':
101| p = (x-0.35, y-0.02)
102| t.set_position(p)
103| continue
104|
105| lbls2 = ['%s (%.2f%%)' % t for t in zip(labs2, data2)]
106| ax2.legend(wdgs2, lbls2, loc=(+0.25, -0.1333), **legendprops)
107|
108| fn = path.join(ImgsPath, Filename)
109| fig.savefig(fn)
110| print('wrote: %s' % fn)
111| print()
112|
113|
114| if __name__ == '__main__':
115| print(argv[0])
116| print()
117| main()
118| print()
119|
120| '''eof'''
121|