1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| class aWRZ(object):
def __init__(self):
self.dico_LexD={}
def addLexD(self, NewLexD,NewPerc):
self.dico_LexD[NewLexD]=NewPerc
def PlotPie(aData,aLabel,acolor, aTitle):
# make a square figure and axes
fig=figure(1, figsize=(10,10))
axes([0.2, 0.2, 0.5, 0.5])
labels = aLabel
fracs = aData
colors= acolor
#explode=(0, 0.0005, 0, 0)
matplotlib.rcParams['font.size'] = 7
pie(fracs, explode=None,labels=labels,
colors=colors,
autopct='%1.1f%%', shadow=True)
title(aTitle, bbox={'facecolor':'0.8', 'pad':5})
fig.savefig(aTitle + 'aquifer.png') #,dpi=100)
close()
import csv
from pylab import *
import numpy
import random as rn
dico_WRZ={}
dico_Legend={}
cr = csv.reader(open("C:/Book1.csv","rb"))
for a_CSV_row in cr:
WC=a_CSV_row[0]
WRZ=a_CSV_row[1]
LexD=a_CSV_row[2]
Perc=a_CSV_row[3]
if dico_WRZ.has_key(WRZ)==False:
dico_WRZ[WRZ]=aWRZ()
dico_WRZ[WRZ].addLexD(LexD,Perc)
#Colors
if dico_Legend.has_key(LexD)==False:
# create hex random color string
rcolor = '#' + "".join(["%02x"%rn.randrange(256) for x in range(3)])
print rcolor
dico_Legend[LexD]=rcolor
for WRZkey in dico_WRZ.keys():
print
print WRZkey
Labels=()
Data=()
Colors=()
Title=WRZkey
for Lexkey in dico_WRZ[WRZkey].dico_LexD.keys():
Labels += (Lexkey,)
Data += (dico_WRZ[WRZkey].dico_LexD[Lexkey],)
Colors += (dico_Legend[Lexkey],)
print Lexkey, dico_WRZ[WRZkey].dico_LexD[Lexkey]
PlotPie(Data,Labels,Colors,Title) |
Partager