z_fill.html
001|
002| from os import path
003| from random import random
004| import numpy as np
005| import matplotlib.pyplot as plt
006| from matplotlib.ticker import MultipleLocator, FormatStrFormatter
007|
008| BasePath = r'C:\CJS\prj\Python\charts'
009| ImgsPath = path.join(BasePath,'img')
010|
011| RoundDn = lambda n,sep: (sep * (n // sep))
012| RoundUp = lambda n,sep: (sep + RoundDn(n,sep))
013|
014|
015| def do_chart_fill ():
016| filename = path.join(ImgsPath,'z_fill.png')
017|
018|
019| N = 10
020| data_0 = [0]+list(range(N))+[N-1]
021| data_1 = [0]+[3.0+((2.0+x) * random()) for x in range(N)]+[0]
022| data_2 = [0]+[3.0+((2.0+x) * random()) for x in range(N)]+[0]
023| data_3 = [0]+[3.0+((2.0+x) * random()) for x in range(N)]+[0]
024|
025| xmin = 0
026| xmax = N-1
027| ymin = 0.0
028| ymax = max(data_1+data_2+data_3)
029| ytop = RoundUp(ymax, 10)
030| xtic = list(range(xmin, xmax))+[xmax]
031| ytic = list(np.arange(ymin, ytop, 5))+[ytop]
032|
033|
034| fig, ax = plt.subplots()
035| fig.suptitle('Filled Line Chart')
036| ax.set_xlabel('X Axis')
037| ax.set_ylabel('Y Axis')
038| ax.set_xlim(xmin, xmax)
039| ax.set_ylim(ymin, ytop)
040|
041| ax.minorticks_on()
042| ax.set_xticks(xtic)
043| ax.set_yticks(ytic)
044| ax.xaxis.set_minor_locator(MultipleLocator(0.333333))
045| ax.tick_params(which='major', axis='both', direction='out', zorder=0)
046| ax.tick_params(which='minor', axis='both', direction='out', zorder=0)
047|
048| ax.grid(which='minor', axis='both', color='#bfbfbf', lw=1.0,ls='-',zorder=0, alpha=1.0)
049| ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.5,ls='-',zorder=1, alpha=1.0)
050|
051| p1 = ax.fill(data_0,data_1, label='Series 1', lw=1.50, color='#dd1111', alpha=0.3, zorder=2)
052| p2 = ax.fill(data_0,data_2, label='Series 2', lw=1.50, color='#11dd11', alpha=0.3, zorder=3)
053| p3 = ax.fill(data_0,data_3, label='Series 3', lw=1.50, color='#1111dd', alpha=0.3, zorder=4)
054| ax.plot(data_0,data_1, lw=1.00, color='#000000', alpha=1.0, zorder=5)
055| ax.plot(data_0,data_2, lw=1.00, color='#000000', alpha=1.0, zorder=5)
056| ax.plot(data_0,data_3, lw=1.00, color='#000000', alpha=1.0, zorder=5)
057|
058| ax.legend(loc='upper left')
059|
060| fig.set_figwidth(8.0)
061| fig.set_figheight(6.0)
062| fig.subplots_adjust(left=0.10, bottom=0.10, right=0.95, top=0.95)
063| fig.savefig(filename)
064|
065|
066|
067| if __name__ == '__main__':
068| do_chart_fill()
069|
070| '''eof'''
071|