z_fancy.html
001|
002| from os import path
003| from random import random
004| import matplotlib.pyplot as plt
005| from matplotlib.ticker import MultipleLocator, FormatStrFormatter
006|
007| BasePath = r'C:\CJS\prj\Python\charts'
008| ImgsPath = path.join(BasePath,'img')
009|
010|
011|
012| def do_chart_fancy ():
013| filename = path.join(ImgsPath,'z_fancy.png')
014| fr = lambda z,r: (float(z)+(float(r)-(random()*(2.0*r))))
015|
016|
017| xi = [n+1 for n in range(30)]
018| ys1 = [fr(75, 20) for n in xi]
019| ys2 = [fr(25, 20) for n in xi]
020| ys3 = [fr(75, 20) for n in xi]
021| ys4 = [fr(25, 20) for n in xi]
022| ys5 = [fr(75, 20) for n in xi]
023| ys6 = [fr(25, 20) for n in xi]
024| xmin, xmax = 0, len(xi)+1
025| ymin, ymax = 0.0, 100.0
026| xt = [1]+list(range(5,xmax,5))
027|
028|
029| fig, ax = plt.subplots()
030| fig.suptitle('Chart', horizontalalignment='left')
031| ax.set_title('Test Data', loc='left', fontsize=13)
032| ax.set_xlabel('X Axis', ha='left', fontsize=11)
033| ax.set_ylabel('Y Axis', fontsize=11)
034| ax.set_xlim(xmin, xmax)
035| ax.set_ylim(ymin, ymax)
036|
037| ax.set_xticks(xt)
038| ax.yaxis.set_major_locator(MultipleLocator(10))
039| ax.tick_params(which='major', axis='both', direction='out')
040| ax.grid(which='major', axis='both', color='#7f7fbf', lw=1.0,ls='-', alpha=1.0, zorder=1)
041|
042| ax.fill_between(xi,ys1,0, label='Chnl.A', color='#00ffff', alpha=0.20, zorder=3)
043| ax.fill_between(xi,ys3,0, label='Chnl.B', color='#ffff00', alpha=0.20, zorder=4)
044| ax.fill_between(xi,ys5,0, label='Chnl.C', color='#ff00ff', alpha=0.20, zorder=5)
045| ax.fill_between(xi,ys2,0, label='Chnl.D', color='#ff0000', alpha=0.20, zorder=6)
046| ax.fill_between(xi,ys4,0, label='Chnl.E', color='#00ff00', alpha=0.20, zorder=7)
047| ax.fill_between(xi,ys6,0, label='Chnl.F', color='#0000ff', alpha=0.20, zorder=8)
048| ax.legend(loc=(+0.70, +0.95), ncol=2, fontsize=8, shadow=True, facecolor='#000000', framealpha=1.0)
049| leg = ax.get_legend()
050| for x in leg.get_texts(): x.set_color('white')
051| for x in leg.get_patches(): x.set_alpha(0.8)
052|
053| fig.set_figwidth(6.4)
054| fig.set_figheight(4.8)
055| fig.subplots_adjust(left=0.12, bottom=0.15, right=0.97, top=0.90)
056| fig.savefig(filename)
057|
058|
059|
060| if __name__ == '__main__':
061| do_chart_fancy()
062|
063| '''eof'''
064|