コード例 #1
0
def plot_cal_bars(data):

    #group data by calendar and week, use units of hours
    weekShow = ((data['Duration'] / np.timedelta64(1, 'h')).groupby(
        data.Calendar).resample('W').sum().unstack(level=0)).round(1)

    #xlabels
    weekShow = weekShow.fillna(value=0)
    weekNames = weekShow.set_index(
        weekShow.index.strftime("%b %d")).index.tolist()
    #mini bar names
    calNames = weekShow.columns.tolist()
    #generate some D3 code
    chart = nvd3.multiBarChart(width=1600, height=400, x_axis_format=None)
    xdata = weekNames
    #add hover tooltips
    extra_serie = {"tooltip": {"y_start": "You spent ", "y_end": " hours"}}
    for cal_name in weekShow:
        chart.add_serie(name=cal_name,
                        y=weekShow[cal_name].tolist(),
                        x=xdata,
                        extra=extra_serie)
    chart.buildhtml()
    #make safe for HTML
    plot = Markup(chart.htmlcontent)
    return plot
コード例 #2
0
def hello():
    output = open('static/index.html', 'w')
    input_data = list(csv.reader(open('dateCrimeOutput.txt', 'rb'), delimiter='\t'))
    chart = multiBarChart(name='multiBarChart', height=800, width=1800, margin_bottom=300, margin_top=40, margin_left=60, margin_right=60)
    crimes = []
    for row in input_data:
        crimes.append([row[0], int(row[1]), int(row[2])])
    crimes = sorted(crimes, key=lambda crimes: crimes[1], reverse=True)
    current_year = None
    i = 0
    for crime in crimes:
        if crime[1] == current_year:
            globals()['xdata%s' % i].append(crime[0])
            globals()['ydata%s' % i].append(crime[2])
        else:
            current_year = crime[1]
            i = i+1
            globals()['year%s' % i] = str(crime[1])
            globals()['ydata%s' % i] = []
            globals()['xdata%s' % i] = []
            globals()['ydata%s' % i].append(crime[2])
            globals()['xdata%s' % i].append(crime[0])


    i = 1
    while True:
        try:
            kwargs1 = {'key': globals()['year%s' % i]}
            chart.add_serie(name=globals()['year%s' % i], y=globals()['ydata%s' % i], x=globals()['xdata%s' % i], **kwargs1)
            i = i + 1
        except:
            break
    chart.buildhtml()
    output.write(chart.htmlcontent)
    return chart.htmlcontent
コード例 #3
0
    def get_result(self, request, graph_type, state_Abrv):

        # define variables
        usResult = request['usResult']
        stateResult = request['stateResult']
        type = graph_type

        # Display pie chart
        if (type == "pieChart"):
            value = int(usResult) - int(stateResult)
            chart = pieChart(name=type,
                             color_category='category20c',
                             height=450,
                             width=450)
            xdata = ["United States", state_Abrv]
            ydata = [int(value), int(stateResult)]
            extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}}
            chart.add_serie(y=ydata, x=xdata, extra=extra_serie)

        # else display bar chart
        else:
            chart = multiBarChart(width=500, height=400, x_axis_format=None)
            xdata = ["United States", state_Abrv]
            ydata = [usResult, stateResult]
            chart.add_serie(name="", y=ydata, x=xdata)
            chart.show_legend = False

        # convert charts into html content (and JavaScript)
        chart.buildcontent()
        result = chart.htmlcontent

        return result
コード例 #4
0
 def test_MultiBarChart(self):
     """Test Multi Bar Chart"""
     type = "MultiBarChart"
     chart = multiBarChart(name=type, height=400)
     nb_element = 10
     xdata = list(range(nb_element))
     ydata = [random.randint(1, 10) for i in range(nb_element)]
     chart.add_serie(y=ydata, x=xdata)
     chart.buildhtml()
コード例 #5
0
ファイル: tests.py プロジェクト: agorrod/python-nvd3
 def test_MultiBarChart(self):
     """Test Multi Bar Chart"""
     type = "MultiBarChart"
     chart = multiBarChart(name=type, height=400)
     nb_element = 10
     xdata = list(range(nb_element))
     ydata = [random.randint(1, 10) for i in range(nb_element)]
     chart.add_serie(y=ydata, x=xdata)
     chart.buildhtml()
コード例 #6
0
    def get_barchart(formatted):
        """ Create a bar chart and return html content """

        chart = multiBarChart(width=1200, height=500, x_axis_format=None)
        xdata = formatted[formatted.keys()[0]].values.tolist()
        ydata1 = formatted[formatted.keys()[1]].values.tolist()
        chart.add_serie(name=formatted.keys()[0], y=ydata1, x=xdata)
        chart.buildhtml()

        with open("test.html", 'w') as fil:
            fil.write(chart.htmlcontent)

        return chart.htmlcontent
コード例 #7
0
ファイル: project.py プロジェクト: Gazillod/PSIT-PROJECT
def build_conclude_graph():
    """This function build the chart template and set the histogram graph with data
    then show about the main cause of situation in 2006-2013 """
    chart = multiBarChart(width = 2040, height = 500, x_axis_format = None)    
    for collum_year in range(1, 9):
        xdata, ydata = [], []
        for i in manage_data():
            cause = ((i[0])[0:6])
            if cause == ' Cause' or cause == ' Other':
                xdata.append(i[0])
                ydata.append(int(i[collum_year]))
            else:
                pass
        chart.add_serie(name = 'THE SITUATION OF TRAFFIC ACCIDENT IN (case)' + str(2005 + collum_year), y = ydata, x = xdata)
    return chart
コード例 #8
0
ファイル: year_53.py プロジェクト: kornasak/Project-PSIT
def chart(name, hs):
    """13.71888 100.52578"""
    chart = multiBarChart(width=250, height=150, x_axis_format=None)
    xdata = ['จำนวนทั้งหมด', 'ไม่สวมหมวก', 'ดื่มสุรา']
    ydata1 = list_hs[hs][0]
    ydata2 = list_hs[hs][1]
    chart.add_serie(name="ชาย", y=ydata1, x=xdata)
    chart.add_serie(name="หญิง", y=ydata2, x=xdata)
    chart.buildhtml()
    file_name = name + str(hs) + ".html"
    text_file = open(file_name, "w")
    text_file.write(chart.htmlcontent)
    print(chart.htmlcontent)
    text_file.close()
    return file_name
コード例 #9
0
ファイル: project.py プロジェクト: Gazillod/PSIT-PROJECT
def build_each_graph(situation):
    """This function build the chart template and set the histogram graph with data
    then show about a cause of the accident that user want to know"""

    chart = multiBarChart(width = 2040, height = 500, x_axis_format = None)    
    for collum_year in range(1, 9):
        xdata, ydata = [], []
        for i in manage_data():
            cause = ((i[0])[0:len(situation[0])])
            if cause == situation[0]:
                xdata.append(i[0])
                ydata.append(int(i[collum_year]))
            else:
                pass
        chart.add_serie(name = 'THE SITUATION OF TRAFFIC ACCIDENT IN (Case)' + str(2005+collum_year), y = ydata, x = xdata)
    return chart
コード例 #10
0
def hello():
    output = open('static/index.html', 'w')
    input_data = list(
        csv.reader(open('dateCrimeOutput.txt', 'rb'), delimiter='\t'))
    chart = multiBarChart(name='multiBarChart',
                          height=800,
                          width=1800,
                          margin_bottom=300,
                          margin_top=40,
                          margin_left=60,
                          margin_right=60)
    crimes = []
    for row in input_data:
        crimes.append([row[0], int(row[1]), int(row[2])])
    crimes = sorted(crimes, key=lambda crimes: crimes[1], reverse=True)
    current_year = None
    i = 0
    for crime in crimes:
        if crime[1] == current_year:
            globals()['xdata%s' % i].append(crime[0])
            globals()['ydata%s' % i].append(crime[2])
        else:
            current_year = crime[1]
            i = i + 1
            globals()['year%s' % i] = str(crime[1])
            globals()['ydata%s' % i] = []
            globals()['xdata%s' % i] = []
            globals()['ydata%s' % i].append(crime[2])
            globals()['xdata%s' % i].append(crime[0])

    i = 1
    while True:
        try:
            kwargs1 = {'key': globals()['year%s' % i]}
            chart.add_serie(name=globals()['year%s' % i],
                            y=globals()['ydata%s' % i],
                            x=globals()['xdata%s' % i],
                            **kwargs1)
            i = i + 1
        except:
            break
    chart.buildhtml()
    output.write(chart.htmlcontent)
    return chart.htmlcontent
コード例 #11
0
def stackedMF():
    output_file = open('literacy_rate_nvd3.html', 'w')
    chart = multiBarChart(width=1000,
                          height=400,
                          x_axis_format=None,
                          color='green')
    data = ['Male', 'Female']
    Arabic_countries = [95, 90]
    Asian_countries = [85, 75]
    African_countries = [56, 71]
    American_countries = [90, 88]
    rest_countries = [95, 93]
    chart.add_serie(name="Arab region", y=Arabic_countries, x=data)
    chart.add_serie(name="Asian region", y=Asian_countries, x=data)
    chart.add_serie(name="African region", y=African_countries, x=data)
    chart.add_serie(name="American region", y=American_countries, x=data)
    chart.add_serie(name=" Rest of world", y=rest_countries, x=data)
    chart.buildhtml()
    display(HTML(chart.htmlcontent))
    output_file.write(chart.htmlcontent)
    output_file.close()
コード例 #12
0
def wealthquintileNAR():
    output_file = open('net_attendance_rate_nvd3.html', 'w')
    chart = multiBarChart(width=1000,
                          height=400,
                          x_axis_format=None,
                          color='green')
    data = ['Poorest', 'Second', 'Middle', 'Fourth', 'Richest']
    Arabic_countries = [92, 95, 96, 97, 97.]
    Asian_countries = [81, 86, 89, 90, 92]
    African_countries = [62, 69, 75, 82, 88]
    American_countries = [91, 94, 95, 96, 97]
    rest_countries = [89, 91, 92, 92, 94]

    chart.add_serie(name="Arab region", y=Arabic_countries, x=data)
    chart.add_serie(name="Asian region", y=Asian_countries, x=data)
    chart.add_serie(name="African region", y=African_countries, x=data)
    chart.add_serie(name="American region", y=American_countries, x=data)
    chart.add_serie(name=" Rest of world", y=rest_countries, x=data)
    chart.buildhtml()
    display(HTML(chart.htmlcontent))
    output_file.write(chart.htmlcontent)

    output_file.close()
コード例 #13
0
ファイル: charts.py プロジェクト: praetore/gamer-agression
def generate_friends_chart(group):
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = ["Followers per user", "Friends per user", "Retweets per post"]
    ydata = [[], []]

    for topics in group:
        index = group.index(topics)
        total_population = []
        for topic in topics:
            population = retrieve_by_topic(topic, "users")
            for p in population:
                total_population.append(p)

        y = ydata[index]
        follow, friend, retw = get_friendship_stats(total_population)
        y.append(follow)
        y.append(friend)
        y.append(retw)

    chart.add_serie(name="Gamers", y=ydata[0], x=xdata)
    chart.add_serie(name="Non-gamers", y=ydata[1], x=xdata)

    str(chart)
    return chart.content
コード例 #14
0
import pandas as pd
import nvd3
from nvd3 import multiBarChart
from IPython.display import Image
from IPython.core.display import display, HTML

df = pd.read_csv("/home/varun/q5-4.6-table.csv")
# saving a file into HTML file
output_file = open('allexam3rwre.html', 'w')
chart = multiBarChart(width=1000,
                      height=400,
                      x_axis_format=None,
                      color='green')
xdata = df['Year']
One = df['Total']
Two = df['Women']
Three = df['Women1']

chart.add_serie(name="Public Sector", y=One, x=xdata)
chart.add_serie(name="Public Sector", y=Two, x=xdata)
chart.add_serie(name="Public Sector", y=Three, x=xdata)
chart.buildhtml()
display(HTML(chart.htmlcontent))
output_file.write(chart.htmlcontent)

# close HTML file
output_file.close()
#>>> ax = sns.barplot(x="day", y="total_bill", hue="sex", data=tips)
コード例 #15
0
ファイル: demo_all.py プロジェクト: imom0/python-nvd3
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(-10, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]
extra_serie = {"tooltip": {"y_start": "", "y_end": " Calls"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " Min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)
#---------------------------------------

type = "multiBarChart"
chart = multiBarChart(name=type, height=350, jquery_on_ready=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(1, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)
chart.buildcontent()

output_file.write(chart.htmlcontent)
#---------------------------------------
コード例 #16
0
    def certification_prob(self, **kwargs):
        '''
        Simple grade distribution.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        '''

        data = self.person[['start_time', 'certified']].copy()
        data.start_time = data.start_time.apply(lambda x: (x - self.cinfo[
            'start_date']).days / 7 if pd.notnull(x) else x)
        data.certified = data.certified.apply(lambda x: 'Certified'
                                              if x == 1 else 'Non-Certified')
        data = pd.crosstab(data.start_time, data.certified).sort_index()

        print data.head()

        # mindate = tmp.index[0] - timedelta(days=21)
        # maxdate = tmp.index[-1] + timedelta(days=21)

        NVD3 = kwargs.get('NVD3', False)

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:

            ### Data
            bins = 50
            hmin = 0.0
            hmax = 1.0
            DATA = self.person[(self.person.grade >= glowbound)]
            Y1, X1 = np.histogram(DATA[DATA.certified == 0].grade.values,
                                  bins=bins,
                                  range=(hmin, hmax))
            Y2, X2 = np.histogram(DATA[DATA.certified == 1].grade.values,
                                  bins=bins,
                                  range=(hmin, hmax))

            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath + 'interactive_grade_distribution_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Certification Bubble Chart: %s" % self._xdata.course_id
            chart = multiBarChart(name=title, height=400)
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(X1)

            extra_serie = {
                "tooltip": {
                    "y_start": "",
                    "y_end": ""
                },
                "color": xff.colors['neutral']
            }
            chart.add_serie(name="Count", y=Y1, x=X1, extra=extra_serie)
            extra_serie = {
                "tooltip": {
                    "y_start": "",
                    "y_end": ""
                },
                "color": xff.colors['institute']
            }
            chart.add_serie(name="Duration", y=Y2, x=X2, extra=extra_serie)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
def Total():
    All_city = []
    All_Geo_x = []
    All_Geo_y = []
    for city in range(len(RdataDaily['features'])):

        Name_Eng = RdataDaily['features'][city]['attributes']["Name_Eng"]
        GEOx = RdataDaily['features'][city]['geometry']['x']
        GEOy = RdataDaily['features'][city]['geometry']['y']

        if Name_Eng not in All_city:
            All_city.append(Name_Eng)
            All_Geo_x.append(GEOx)
            All_Geo_y.append(GEOy)

    # print(len(All_city)) # print the length
    All_confirmed = []
    All_Deaths = []
    All_Tested = []
    All_Recovered = []

    for city in range(len(All_city)):

        Confirmed = 0
        Deaths = 0
        Tested = 0
        Recovered = 0
        date2 = []

        # Check for the last date
        for cases in range(len(RdataDaily['features'])):
            date = RdataDaily['features'][cases]['attributes']["Reportdt"]
            if date not in date2:
                date2.append(date)
        date_now = max(date2)

        # Check for Confimed Cases
        for cases in range(len(RdataDaily['features'])):
            check = RdataDaily['features'][cases]['attributes']["Name_Eng"]
            date = RdataDaily['features'][cases]['attributes']["Reportdt"]
            if All_city[city] == check and date == date_now:
                Deaths += RdataDaily['features'][cases]['attributes']["Deaths"]
                Recovered += RdataDaily['features'][cases]['attributes'][
                    "Recovered"]
                Confirmed += RdataDaily['features'][cases]['attributes'][
                    "Confirmed"]

        All_confirmed.append(Confirmed)
        All_Deaths.append(Deaths)
        All_Recovered.append(Recovered)

    rec = 0
    deaths = 0
    conf = 0

    Total_file = open('Total.json', 'w+')

    All_info2 = []
    for cases in range(len(All_city)):
        a = {
            "city": All_city[cases],
            "Deaths": All_Deaths[cases],
            "Recovered": All_Recovered[cases],
            "Confirmed": All_confirmed[cases]
        }

        All_info2.append(dict(a))

        conf += All_confirmed[cases]
        rec += All_Recovered[cases]
        deaths += All_Deaths[cases]

    print(f"Total Confirmed: {str(conf)}")
    print(f"Total Recovered: {str(rec)}")
    print(f"Total Deaths: 	 {str(deaths)}")

    Total_file.write(json.dumps(All_info2))
    Total_file.close()

    New_Geo_x = []
    New_Geo_y = []
    for Infected in range(len(All_info2)):
        infction = All_info2[Infected]['Confirmed']

        if infction != 0:
            New_Geo_x.append(All_Geo_x[Infected])
            New_Geo_y.append(All_Geo_y[Infected])

    random = []
    for i in range(len(New_Geo_x)):
        random.append(0.009)

    gmap5 = gmplot.GoogleMapPlotter(23.68363, 45.76787, 6)
    gmap5.heatmap(New_Geo_y,
                  New_Geo_x,
                  radius=20,
                  gradient=[(0, 0, 255, 0), (0, 255, 0, 0.9), (255, 0, 0, 1)])
    gmap5.draw('map.html')

    Chart_all = open('Visiual.html', 'w+')

    chart = multiBarChart(width=3000, height=1000, x_axis_format=None)
    chart.add_serie(name="Recovered 1", y=All_Recovered, x=All_city)
    chart.add_serie(name="Infected 2", y=All_confirmed, x=All_city)
    chart.buildhtml()
    Chart_all.write(chart.htmlcontent)
    Chart_all.close()
コード例 #18
0
ファイル: outcomes.py プロジェクト: codyaustun/xtools
    def grade_distribution(self,**kwargs):
        '''
        Simple grade distribution.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        '''

        NVD3 = kwargs.get('NVD3',False)

        if self.person.grade.count() < 50:
            print "Not enough grade information. Return without grade distribution."
            return None

        bins = 50 
        hmin = 0.0 #self.person['grade'].min()
        hmax = 1.0 #self.person['grade'].max()
        glowbound = 0.1

        ### Plot
        fig = plt.figure(figsize=(12,7))
        ax1 = fig.add_subplot(1,1,1)

        self.person[(self.person.grade>=glowbound) & (self.person.certified==0)]['grade'].hist(ax=ax1,bins=bins,range=(hmin,hmax),log=False,cumulative=0,
                                                 color=xff.colors['neutral'],edgecolor=xff.colors['neutral'])
        
        self.person[(self.person.grade>=glowbound) & (self.person.certified==1)]['grade'].hist(ax=ax1,bins=bins,range=(hmin,hmax),log=False,cumulative=0,
                                                 color=xff.colors['institute'],edgecolor=xff.colors['institute'],alpha=0.8)
        
        xlab = 'Grade'
        #ax1.set_xlabel(r'%s' % (xlab),fontdict={'fontsize': 30,'style': 'oblique'})
        #ax1.set_ylabel(r'Count (log scale)',fontdict={'fontsize': 30,'style': 'oblique'})
        ax1.set_xlim(0,hmax)
        ax1.set_ylim(1,)
        ax1.legend(['$Non-Certified$','$Certified$'],loc=1,prop={'size':24},frameon=False)
        ax1.set_xticklabels([r'$%.1f$' % x for x in ax1.get_xticks()],fontsize=30)
        ax1.set_yticklabels([r'$%d$' % y for y in ax1.get_yticks()],fontsize=30)

        ### Generalized Plotting functions
        figsavename = self.figpath+'grade_distribution_'+self.nickname.replace('.','_')
        xff.texify(fig,ax1,
                   xlabel='Grade (> %.2f)' % (glowbound),
                   ylabel='Count',
                   gridb='y',
                   figsavename=figsavename+'.png')

        
        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            
            ### Data
            bins = 50
            hmin = 0.0
            hmax = 1.0
            DATA = self.person[(self.person.grade>=glowbound)]
            Y1,X1 = np.histogram(DATA[DATA.certified==0].grade.values,bins=bins,range=(hmin,hmax))
            Y2,X2 = np.histogram(DATA[DATA.certified==1].grade.values,bins=bins,range=(hmin,hmax))

            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath+'interactive_grade_distribution_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Grade Distribution: %s" % self._xdata.course_id
            chart = multiBarChart(name=title, height=400)
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(X1)

            extra_serie = {"tooltip": {"y_start": "", "y_end": ""},
                           "color":xff.colors['neutral']
                           }
            chart.add_serie(name="Count", y=Y1, x=X1, extra=extra_serie)
            extra_serie = {"tooltip": {"y_start": "", "y_end": ""},
                           "color":xff.colors['institute']
                           }
            chart.add_serie(name="Duration", y=Y2, x=X2, extra=extra_serie)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
コード例 #19
0
    def level_of_education(self, **kwargs):
        '''
        Plot Level of Education Attained; typically taken from the edX enrollment questionairre.
        '''
        """
        Creates distribution of highest level of education attained.
       
        Parameters (generated during class initialization)
        ----------
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        NVD3 = kwargs.get('NVD3', False)

        ### Level of Education (LoE)
        ### Data
        eddict = {
            'el': "Less\ than$\n$ Secondary",
            'jhs': "Less\ than$\n$ Secondary",
            'none': "Less\ than$\n$ Secondary",
            'hs': "Secondary",
            'a': "Secondary",
            'b': "Bachelor\'s",
            'm': "Master\'s",
            'p_se': "Doctorate",
            'p_oth': "Doctorate",
            'p': "Doctorate",
            'other': None,
            'NA': None,
            'nan': None,
        }

        edlist = [
            "Less\ than$\n$ Secondary", "Secondary", "Bachelor\'s",
            "Master\'s", "Doctorate"
        ]
        trim_data = self.person[(self.person.registered == 1)
                                & (self.person.user_id > 156633)]

        edlevels = trim_data.LoE.apply(lambda x: eddict[str(x)] if x in eddict.
                                       keys() else None).value_counts()[edlist]
        if trim_data[trim_data.certified ==
                     1].username.count() > self.mincerts:
            certs = trim_data[trim_data.certified == 1].LoE.apply(
                lambda x: eddict[str(x)]
                if x in eddict.keys() else None).value_counts()[edlist]
        else:
            certs = pd.Series(index=edlevels.index)

        edlevels = pd.concat([edlevels, certs],
                             join='inner',
                             axis=1,
                             keys=['$Non-Certified$', '$Certified$'])
        edlevels = 100. * edlevels / edlevels.sum()
        edlevels = edlevels.apply(lambda x: np.round(x, 1))

        #print edlevels

        #Plot
        fig = plt.figure(figsize=(12, 6))
        ax1 = fig.add_subplot(1, 1, 1)

        edlevels.plot(ax=ax1,
                      kind='bar',
                      color=[xff.colors['neutral'], xff.colors['institute']],
                      rot=40)

        ### Plot Details
        ax1.set_xticklabels([r'$%s$' % x for x in edlist])
        ax1.set_yticklabels(
            [r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],
            fontsize=30)
        ax1.legend(loc=2, prop={'size': 22}, frameon=False)

        ### Generalized Plotting functions
        figsavename = self.figpath + 'loe_distribution_' + self.nickname.replace(
            '.', '_')
        print figsavename
        xff.texify(fig,
                   ax1,
                   xlabel=None,
                   ylabel=None,
                   figsavename=figsavename + '.png')

        ### Output JSON Records
        #cc.name = 'value'
        #cc = cc.reset_index().rename(columns={'index':'label'})
        #cc.dropna().to_json(figsavename+'.json',orient='records')

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath + 'interactive_edlevel_distribution_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Education Level Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'

            chart = multiBarChart(name=charttype,
                                  height=350,
                                  x_axis_format="",
                                  y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(edlevels)
            X = [
                x.replace('\ ', ' ').replace('$\n$', ' ')
                for x in edlevels.index
            ]  #list(range(nb_element))
            Y1 = edlevels.ix[:, '$Non-Certified$'].values
            Y2 = edlevels.ix[:, '$Certified$'].values

            ### Series 1
            extra_serie1 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['neutral'],
                "format": ".1f"
            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)

            ### Series 2
            extra_serie2 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['institute'],
                "format": ".1f"
            }
            chart.add_serie(name="Certificate Earners",
                            y=Y2,
                            x=X,
                            extra=extra_serie2)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
コード例 #20
0
ファイル: demographics.py プロジェクト: codyaustun/xtools
    def country_of_origin(self,**kwargs):
        """
        Creates figures for the top "ccnum" of enrolled countries.
       
        Parameters (generated during class initialization)
        ----------
        ccnum = number of requested countries to be plotted. Max 25 for plotting issues.
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """
        
        NVD3 = kwargs.get('NVD3',False)

        ccnum = kwargs.get('ccnum',10)

        cc = self.person.final_cc.value_counts().order(ascending=False)
        if self.person[self.person.certified==1].username.count() > self.mincerts:
            certs = self.person[self.person.certified==1].final_cc.value_counts()
        else:
            certs = pd.Series(index=cc.index)

        cc = pd.concat([cc,certs],join='inner',axis=1,keys=['$Non-Certified$','$Certified$'])
        cc = cc.sort('$Non-Certified$',ascending=False)[0:ccnum]
        perc = 100.*cc/cc.sum()
        perc = perc.apply(lambda x: np.round(x,1))
        #print perc

        fig = plt.figure(figsize=(12,6))
        ax1 = fig.add_subplot(1,1,1)
        perc.plot(ax=ax1,kind='bar',color=[xff.colors['neutral'],xff.colors['institute']],rot=40,)

        ### Plot Details
        ax1.set_xticklabels([r'$%s$' % x for x in perc.index])
        ax1.set_yticklabels([r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],fontsize=30)
        ax1.legend(loc=1,prop={'size':28},frameon=False)
        
        ### Generalized Plotting functions
        figsavename = self.figpath+'country_geoloc_distribution_'+self.nickname.replace('.','_')
        print figsavename
        xff.texify(fig,ax1,xlabel='Country Code',ylabel=None,figsavename=figsavename+'.png')

        ### Output JSON Records
        #cc.name = 'value'
        #cc = cc.reset_index().rename(columns={'index':'label'})
        #cc.dropna().to_json(figsavename+'.json',orient='records')
        

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath+'interactive_country_distribution_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Education Level Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = multiBarChart(name=charttype, height=350, x_axis_format="", y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(perc)
            X = perc.index #list(range(nb_element))
            Y1 = perc.ix[:,'$Non-Certified$'].values
            Y2 = perc.ix[:,'$Certified$'].values

            ### Series 1
            extra_serie1 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['neutral'],
                            "format":".1f"
                            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)
            
            ### Series 2
            extra_serie2 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['institute'],
                            "format":".1f"
                            }
            chart.add_serie(name="Certificate Earners", y=Y2, x=X, extra=extra_serie2)
            
            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
コード例 #21
0
ファイル: demographics.py プロジェクト: codyaustun/xtools
    def level_of_education(self,**kwargs):
        '''
        Plot Level of Education Attained; typically taken from the edX enrollment questionairre.
        '''
        """
        Creates distribution of highest level of education attained.
       
        Parameters (generated during class initialization)
        ----------
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """
        
        NVD3 = kwargs.get('NVD3',False)

        ### Level of Education (LoE)
        ### Data
        eddict = {'el': "Less\ than$\n$ Secondary",'jhs': "Less\ than$\n$ Secondary",'none':"Less\ than$\n$ Secondary",
                  'hs':"Secondary",'a':"Secondary",
                  'b':"Bachelor\'s",
                  'm': "Master\'s",
                  'p_se': "Doctorate",'p_oth': "Doctorate",'p': "Doctorate",
                  'other': None,'NA':None,'nan':None,
                  }

        edlist = ["Less\ than$\n$ Secondary","Secondary","Bachelor\'s","Master\'s","Doctorate"]
        trim_data = self.person[(self.person.registered==1) & (self.person.user_id>156633)]
        
        edlevels = trim_data.LoE.apply(lambda x: eddict[str(x)] if x in eddict.keys() else None).value_counts()[edlist]
        if trim_data[trim_data.certified==1].username.count() > self.mincerts:
            certs = trim_data[trim_data.certified==1].LoE.apply(lambda x: eddict[str(x)] if x in eddict.keys() else None).value_counts()[edlist]
        else:
            certs = pd.Series(index=edlevels.index)    

        edlevels = pd.concat([edlevels,certs],join='inner',axis=1,keys=['$Non-Certified$','$Certified$']) 
        edlevels = 100.*edlevels/edlevels.sum()
        edlevels = edlevels.apply(lambda x: np.round(x,1))

        #print edlevels
        
        #Plot
        fig = plt.figure(figsize=(12,6))
        ax1 = fig.add_subplot(1,1,1)
        
        edlevels.plot(ax=ax1,kind='bar',color=[xff.colors['neutral'],xff.colors['institute']],rot=40)
        
        ### Plot Details
        ax1.set_xticklabels([r'$%s$' % x for x in edlist])
        ax1.set_yticklabels([r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],fontsize=30)
        ax1.legend(loc=2,prop={'size':22},frameon=False)
        
        ### Generalized Plotting functions
        figsavename = self.figpath+'loe_distribution_'+self.nickname.replace('.','_')
        print figsavename
        xff.texify(fig,ax1,xlabel=None,ylabel=None,figsavename=figsavename+'.png')

        ### Output JSON Records
        #cc.name = 'value'
        #cc = cc.reset_index().rename(columns={'index':'label'})
        #cc.dropna().to_json(figsavename+'.json',orient='records')


        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath+'interactive_edlevel_distribution_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Education Level Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'

            chart = multiBarChart(name=charttype, height=350, x_axis_format="", y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(edlevels)
            X = [ x.replace('\ ',' ').replace('$\n$',' ') for x in edlevels.index ] #list(range(nb_element))
            Y1 = edlevels.ix[:,'$Non-Certified$'].values
            Y2 = edlevels.ix[:,'$Certified$'].values

            ### Series 1
            extra_serie1 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['neutral'],
                            "format":".1f"
                            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)
            
            ### Series 2
            extra_serie2 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['institute'],
                            "format":".1f"
                            }
            chart.add_serie(name="Certificate Earners", y=Y2, x=X, extra=extra_serie2)
            
            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()


        return None
コード例 #22
0
ファイル: demographics.py プロジェクト: codyaustun/xtools
    def age(self,**kwargs):
        """
        Creates gender distribution figures.
       
        Parameters (generated during class initialization)
        ----------
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        NVD3 = kwargs.get('NVD3',False)

        ### Removes those users not having the option to fill in edX registration data.
        trim_data = self.person[(self.person.registered==1) & (self.person.user_id>156633)]
        # Add age column from year_of_birth
        trim_data['age'] = trim_data['YoB'].apply(lambda x: datetime.datetime.now().year - x if isinstance(x,int) else None)

        age = trim_data.age.dropna()
        h,e = np.histogram(age.values,bins=9,range=(0,90))
        age = pd.Series(data=h,index=['0-9','10-19','20-29','30-39','40-49','50-59','60-69','70-79','80-89'])
        
        certs = trim_data[trim_data.certified==1]
        if certs.username.count() > self.mincerts:
            certs = certs.age.dropna()
            h,e = np.histogram(certs.values,bins=9,range=(0,90))
            certs = pd.Series(data=h,index=['0-9','10-19','20-29','30-39','40-49','50-59','60-69','70-79','80-89'])
        else:
            certs = pd.Series(index=age.index)

        age = pd.concat([age,certs],join='inner',axis=1,keys=['$Non-Certified$','$Certified$']) 
        age = 100.*age/age.sum()
        age = age.apply(lambda x: np.round(x,1))
        #print age



        #----------------------------------------------------------------
        ### Static Matplotlib PNG
        fig = plt.figure(figsize=(12,6))
        ax1 = fig.add_subplot(1,1,1)
        age.plot(ax=ax1,kind='bar',color=[xff.colors['neutral'],xff.colors['institute']],rot=40,)

        ### Plot Details
        ax1.set_xticklabels([r'$%s$' % x for x in age.index])
        ax1.set_yticklabels([r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],fontsize=30)
        ax1.legend(loc=1,prop={'size':28},frameon=False)
        
        ### Generalized Plotting functions
        figsavename = self.figpath+'age_distribution_'+self.nickname.replace('.','_')
        print figsavename
        xff.texify(fig,ax1,xlabel='Age',ylabel=None,figsavename=figsavename+'.png')

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath+'interactive_age_distribution_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Age Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = multiBarChart(name=charttype, height=350, x_axis_format="", y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(age)
            X = age.index #list(range(nb_element))
            Y1 = age['$Non-Certified$'].values
            Y2 = age['$Certified$'].values

            ### Series 1
            extra_serie1 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['neutral'],
                            "format":".1f"
                            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)
            
            ### Series 2
            extra_serie2 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['institute'],
                            "format":".1f"
                            }
            chart.add_serie(name="Certificate Earners", y=Y2, x=X, extra=extra_serie2)
            
            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()


        return None
コード例 #23
0
ファイル: demographics.py プロジェクト: codyaustun/xtools
    def gender(self,**kwargs):
        """
        Creates gender distribution figures.
       
        Parameters (generated during class initialization)
        ----------
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """
        
        NVD3 = kwargs.get('NVD3',False)

        ### Removes those users not having the option to fill in edX registration data.
        trim_data = self.person[(self.person.registered==1) & (self.person.user_id>156633)]

        ### Data
        gdict =  {'f': "$Female$",'m': "$Male$",'o':"$Other$"}
        glist = ['$Female$','$Male$']

        ### Munge and Plot
        gender = trim_data.gender.dropna().apply(lambda x: gdict[x]).value_counts()
        #print gender
        certs = trim_data[trim_data.certified==1]
        if certs.username.count() > self.mincerts:
            certs = certs.gender.dropna().apply(lambda x: gdict[x]).value_counts()
        else:
            certs = pd.Series(index=gender.index)    

        gender = pd.concat([gender,certs],join='inner',axis=1,keys=['$Non-Certified$','$Certified$']) 
        gender = 100.*gender/gender.sum()
        gender = gender.apply(lambda x: np.round(x,1))

        fig = plt.figure(figsize=(12,6))
        ax1 = fig.add_subplot(1,1,1)
        gender.ix[glist,:].plot(ax=ax1,kind='bar',color=[xff.colors['neutral'],xff.colors['institute']],rot=0)

        ### Plot Details
        ax1.set_xticklabels([r'%s' % x for x in glist])
        ax1.set_yticklabels([r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],fontsize=30)
        ax1.legend(loc=2,prop={'size':28},frameon=False)

        ### Generalized Plotting functions
        figsavename = self.figpath+'gender_distribution_'+self.nickname.replace('.','_')
        print figsavename
        xff.texify(fig,ax1,xlabel=None,ylabel='Count',figsavename=figsavename+'.png')

        # ### Output JSON Records
        # gender.name = 'value'
        # gender = gender.reset_index().rename(columns={'index':'label'})
        # gender.dropna().to_json(figsavename+'.json',orient='records')


        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            
            'http://nvd3.org/examples/pie.html'
            

            X = [ x.replace('$','') for x in gender.index ]
            Y1 = gender.ix[glist,'$Non-Certified$'].values
            Y2 = gender.ix[glist,'$Certified$'].values

            #----------------------------------------------------------------
            ### BAR Chart
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath+'interactive_gender_distribution_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Gender Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = multiBarChart(name=charttype, height=350, x_axis_format="", y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(gender.ix[glist,:])
            

            ### Series 1
            extra_serie1 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['neutral'],
                            "format":".1f"
                            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)
            
            ### Series 2
            extra_serie2 = {"tooltip": {"y_start": "", "y_end": "%"},
                            "color":xff.colors['institute'],
                            "format":".1f"
                            }
            chart.add_serie(name="Certificate Earners", y=Y2, x=X, extra=extra_serie2)
            
            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()


            #----------------------------------------------------------------
            ### Pie Chart
            from nvd3 import pieChart

            ### Output File
            figsavename = self.figpath+'interactive_gender_piechart_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Gender Pie Chart: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = pieChart(name=charttype, color_category='category20c', height=400, width=400)
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")

            extra_serie = {"tooltip": {"y_start": "", "y_end": " certified"}}

            chart.add_serie(y=Y1, x=X, extra=extra_serie)
            
            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()



        return None
コード例 #24
0
d66.columns = ['Developing']
d66

#cell 81
res6 = pd.concat([d6, d66], axis=1, join_axes=[d6.index])
res6

#cell 82
frames = [res,res1,res2,res3,res4,res5,res6]

#cell 83
final_frames = pd.concat(frames)
final_frames

#cell 84
chart = multiBarChart(width=1100, height=500, x_axis_format=None)
causes = list(final_frames.index)
Developed = list(final_frames.Developed)
Developing = list(final_frames.Developing)
chart.add_serie(name="Developed", y=Developed, x=causes)
chart.add_serie(name="Developing", y=Developing, x=causes)
chart.buildhtml()
display(HTML(chart.htmlcontent))

#cell 85
#get_ipython().magic('matplotlib nbagg')
#final_frames.plot(kind='barh', title='Variations of the diseases for under 5yrs of age', rot=0, color=(['g','y']),
#                  stacked=True, figsize=(12, 6), edgecolor='b', linewidth=1, fontsize='13', )
#plt.ylabel('<------ Cause of death ------>', fontsize=14, color='b')
#plt.xlabel('<------ Percentage aggregated values ------>', fontsize=14, color='b')
import pandas as pd
import nvd3
from nvd3 import multiBarChart
from IPython.display import Image
from IPython.core.display import display, HTML
#
output_file = open('china.html', 'w')
chart = multiBarChart(width=1250, height=400, x_axis_format=None, color='blue')
xdata = ['1990.5', '1995.5', '2000.5', '2005.5', '2010.5', '2015.5']
ylower = [49.6, 44.8, 34.9, 22.5, 14.7, 9]
ymedian = [53.8, 47.5, 36.9, 24, 15.7, 10.7]
yupper = [58.8, 50.4, 39.2, 25.5, 16.7, 12.7]
chart.add_serie(name="Upper", y=yupper, x=xdata)
chart.add_serie(name="Median", y=ymedian, x=xdata)
chart.add_serie(name="Lower", y=ylower, x=xdata)
chart.set_containerheader(
    "<h2>Child Mortality rate for China from 1990.5 to 2015.5<h2>")
chart.buildhtml()
display(HTML(chart.htmlcontent))
output_file.write(chart.htmlcontent)
output_file.close()
コード例 #26
0
ファイル: demo_all.py プロジェクト: cmorgan/python-nvd3
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(-10, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]
extra_serie = {"tooltip": {"y_start": "", "y_end": " Calls"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " Min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)
#---------------------------------------

type = "multiBarChart"
chart = multiBarChart(name=type, height=350, jquery_on_ready=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(1, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)
chart.buildcontent()

output_file.write(chart.htmlcontent)
#---------------------------------------
コード例 #27
0
ファイル: demo_all.py プロジェクト: jordanvg/python-nvd3
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(-10, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]
extra_serie = {"tooltip": {"y_start": "", "y_end": " Calls"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " Min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)

chart.buildhtml()

output_file.write(chart.htmlcontent)
#---------------------------------------

type = "multiBarChart"
chart = multiBarChart(name=type, height=350)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(1, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)
chart.buildhtml()

output_file.write(chart.htmlcontent)
#---------------------------------------
コード例 #28
0
    def country_of_origin(self, **kwargs):
        """
        Creates figures for the top "ccnum" of enrolled countries.
       
        Parameters (generated during class initialization)
        ----------
        ccnum = number of requested countries to be plotted. Max 25 for plotting issues.
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        NVD3 = kwargs.get('NVD3', False)

        ccnum = kwargs.get('ccnum', 10)

        cc = self.person.final_cc.value_counts().order(ascending=False)
        if self.person[self.person.certified ==
                       1].username.count() > self.mincerts:
            certs = self.person[self.person.certified ==
                                1].final_cc.value_counts()
        else:
            certs = pd.Series(index=cc.index)

        cc = pd.concat([cc, certs],
                       join='inner',
                       axis=1,
                       keys=['$Non-Certified$', '$Certified$'])
        cc = cc.sort('$Non-Certified$', ascending=False)[0:ccnum]
        perc = 100. * cc / cc.sum()
        perc = perc.apply(lambda x: np.round(x, 1))
        #print perc

        fig = plt.figure(figsize=(12, 6))
        ax1 = fig.add_subplot(1, 1, 1)
        perc.plot(
            ax=ax1,
            kind='bar',
            color=[xff.colors['neutral'], xff.colors['institute']],
            rot=40,
        )

        ### Plot Details
        ax1.set_xticklabels([r'$%s$' % x for x in perc.index])
        ax1.set_yticklabels(
            [r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],
            fontsize=30)
        ax1.legend(loc=1, prop={'size': 28}, frameon=False)

        ### Generalized Plotting functions
        figsavename = self.figpath + 'country_geoloc_distribution_' + self.nickname.replace(
            '.', '_')
        print figsavename
        xff.texify(fig,
                   ax1,
                   xlabel='Country Code',
                   ylabel=None,
                   figsavename=figsavename + '.png')

        ### Output JSON Records
        #cc.name = 'value'
        #cc = cc.reset_index().rename(columns={'index':'label'})
        #cc.dropna().to_json(figsavename+'.json',orient='records')

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath + 'interactive_country_distribution_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Education Level Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = multiBarChart(name=charttype,
                                  height=350,
                                  x_axis_format="",
                                  y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(perc)
            X = perc.index  #list(range(nb_element))
            Y1 = perc.ix[:, '$Non-Certified$'].values
            Y2 = perc.ix[:, '$Certified$'].values

            ### Series 1
            extra_serie1 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['neutral'],
                "format": ".1f"
            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)

            ### Series 2
            extra_serie2 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['institute'],
                "format": ".1f"
            }
            chart.add_serie(name="Certificate Earners",
                            y=Y2,
                            x=X,
                            extra=extra_serie2)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
コード例 #29
0
ファイル: demo_all.py プロジェクト: RodrigoPrior/python-nvd3
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(-10, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]
extra_serie = {"tooltip": {"y_start": "", "y_end": " Calls"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " Min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)

chart.buildhtml()

output_file.write(chart.htmlcontent)
#---------------------------------------

type = "multiBarChart"
chart = multiBarChart(name=type, height=350)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(1, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)
chart.buildhtml()

output_file.write(chart.htmlcontent)
#---------------------------------------
コード例 #30
0
        data.append(information_per_simbol(freq))
        #print '%s : %f' % ( letter, counter[letter]/float(sum_all_letters) )
    return data


# https://plus.maths.org/MI/56c09cb543ec31341504b1627e490cb7/images/img-0008.png
# formula.
def information_per_simbol(data):
    return -data * math.log(data, 2)


# Open File to write the D3 Graph
output_file = open('view.html', 'w')
type = 'Calculo: informacao por simbolo'
chart = multiBarChart(color_category='category20c',
                      width=900,
                      height=600,
                      x_axis_format=None)
chart.set_containerheader(
    "\n\n<h2>" + type +
    "\n\n<img src='https://plus.maths.org/MI/56c09cb543ec31341504b1627e490cb7/images/img-0008.png' /> <br> Baseado na frequencia de ocorrencia cada Letra</h2>\n\n"
)
# Isso cria o html do grafico

#esses sao os dados - letters in lowecase ascii
xdata = ascii_lowercase
# source http://docente.ifrn.edu.br/paulomartins/livros-classicos-de-literatura/dom-casmurro-de-machado-de-assis.-pdf/at_download/file
# to txt
pt_br = count_letters_in_file('machado_pt-br.txt')
# source https://raw.githubusercontent.com/bbejeck/hadoop-algorithms/master/src/shakespeare.txt
en_us = count_letters_in_file('shakespeare_en-us.txt')
ydata_pt_br = array_of_distribution_letters(pt_br)
コード例 #31
0
ファイル: examples01.py プロジェクト: B-Rich/python-nvd3
type = "pieChart"
chart = pieChart(name=type, height=400, width=400)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
xdata = [
    "Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Pineapple"
]
ydata = [3, 4, 0, 1, 5, 7, 3]

chart.add_serie(y=ydata, x=xdata)
chart.buildhtml()
output_file.write(chart.htmlcontent)
#---------------------------------------

type = "multiBarChart"
chart = multiBarChart(name=type, height=350)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 10
xdata = range(nb_element)
ydata = [random.randint(1, 10) for i in range(nb_element)]
ydata2 = map(lambda x: x * 2, ydata)
ydata3 = map(lambda x: x * 3, ydata)
ydata4 = map(lambda x: x * 4, ydata)

chart.add_serie(y=ydata, x=xdata)
chart.add_serie(y=ydata2, x=xdata)
#chart.add_serie(y=ydata3, x=xdata)
chart.buildhtml()

output_file.write(chart.htmlcontent)
#---------------------------------------
コード例 #32
0
ファイル: outcomes.py プロジェクト: codyaustun/xtools
    def certification_prob(self,**kwargs):
        '''
        Simple grade distribution.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        '''

        data = self.person[['start_time','certified']].copy()
        data.start_time = data.start_time.apply(lambda x: (x-self.cinfo['start_date']).days/7 if pd.notnull(x) else x)
        data.certified = data.certified.apply(lambda x: 'Certified' if x == 1 else 'Non-Certified')
        data = pd.crosstab(data.start_time,data.certified).sort_index()

        print data.head()

        # mindate = tmp.index[0] - timedelta(days=21)
        # maxdate = tmp.index[-1] + timedelta(days=21)

        NVD3 = kwargs.get('NVD3',False)
        
        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            
            ### Data
            bins = 50
            hmin = 0.0
            hmax = 1.0
            DATA = self.person[(self.person.grade>=glowbound)]
            Y1,X1 = np.histogram(DATA[DATA.certified==0].grade.values,bins=bins,range=(hmin,hmax))
            Y2,X2 = np.histogram(DATA[DATA.certified==1].grade.values,bins=bins,range=(hmin,hmax))

            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath+'interactive_grade_distribution_'+self.nickname+'.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Certification Bubble Chart: %s" % self._xdata.course_id
            chart = multiBarChart(name=title, height=400)
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(X1)

            extra_serie = {"tooltip": {"y_start": "", "y_end": ""},
                           "color":xff.colors['neutral']
                           }
            chart.add_serie(name="Count", y=Y1, x=X1, extra=extra_serie)
            extra_serie = {"tooltip": {"y_start": "", "y_end": ""},
                           "color":xff.colors['institute']
                           }
            chart.add_serie(name="Duration", y=Y2, x=X2, extra=extra_serie)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
コード例 #33
0
ファイル: gen.py プロジェクト: nxroulette/count_tax
headhtml = """<!DOCTYPE html>
<html lang="th">
    <head>
        <meta charset="utf-8" />
        <link href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.css" rel="stylesheet" />
        <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.js"></script>
        <title>2014 Annual Survey of State Government Tax Collections</title>
    </head>
    <body>
    <center><h1>2014 Annual Survey of State Government Tax Collections</h1></center>
"""

pattern = {"tooltip": {"y_start": "", "y_end": " Million USD"}}

chart = multiBarChart(width=1024, height=768, x_axis_format=None)
chart1 = pieChart(name="chart1", color_category="category20c", height=800, width=768)

chart1.add_serie(y=total_taxes, x=states, extra={"tooltip": {"y_start": "", "y_end": " %"}})
chart1.buildcontent()

chart.add_serie(name="chart", y=total_taxes, x=states)
chart.buildcontent()

file.write(headhtml)

file.write("<center><h2>All Tax Collections By States</h2></center>")
file.write("<center>")
file.write(chart1.htmlcontent)
file.write("</center>")
file.write("<center><h2>State Government Tax CollectionsTax Collections By Category</h2></center>")
コード例 #34
0
    def grade_distribution(self, **kwargs):
        '''
        Simple grade distribution.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        '''

        NVD3 = kwargs.get('NVD3', False)

        if self.person.grade.count() < 50:
            print "Not enough grade information. Return without grade distribution."
            return None

        bins = 50
        hmin = 0.0  #self.person['grade'].min()
        hmax = 1.0  #self.person['grade'].max()
        glowbound = 0.1

        ### Plot
        fig = plt.figure(figsize=(12, 7))
        ax1 = fig.add_subplot(1, 1, 1)

        self.person[(self.person.grade >= glowbound)
                    & (self.person.certified == 0)]['grade'].hist(
                        ax=ax1,
                        bins=bins,
                        range=(hmin, hmax),
                        log=False,
                        cumulative=0,
                        color=xff.colors['neutral'],
                        edgecolor=xff.colors['neutral'])

        self.person[(self.person.grade >= glowbound)
                    & (self.person.certified == 1)]['grade'].hist(
                        ax=ax1,
                        bins=bins,
                        range=(hmin, hmax),
                        log=False,
                        cumulative=0,
                        color=xff.colors['institute'],
                        edgecolor=xff.colors['institute'],
                        alpha=0.8)

        xlab = 'Grade'
        #ax1.set_xlabel(r'%s' % (xlab),fontdict={'fontsize': 30,'style': 'oblique'})
        #ax1.set_ylabel(r'Count (log scale)',fontdict={'fontsize': 30,'style': 'oblique'})
        ax1.set_xlim(0, hmax)
        ax1.set_ylim(1, )
        ax1.legend(['$Non-Certified$', '$Certified$'],
                   loc=1,
                   prop={'size': 24},
                   frameon=False)
        ax1.set_xticklabels([r'$%.1f$' % x for x in ax1.get_xticks()],
                            fontsize=30)
        ax1.set_yticklabels([r'$%d$' % y for y in ax1.get_yticks()],
                            fontsize=30)

        ### Generalized Plotting functions
        figsavename = self.figpath + 'grade_distribution_' + self.nickname.replace(
            '.', '_')
        xff.texify(fig,
                   ax1,
                   xlabel='Grade (> %.2f)' % (glowbound),
                   ylabel='Count',
                   gridb='y',
                   figsavename=figsavename + '.png')

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:

            ### Data
            bins = 50
            hmin = 0.0
            hmax = 1.0
            DATA = self.person[(self.person.grade >= glowbound)]
            Y1, X1 = np.histogram(DATA[DATA.certified == 0].grade.values,
                                  bins=bins,
                                  range=(hmin, hmax))
            Y2, X2 = np.histogram(DATA[DATA.certified == 1].grade.values,
                                  bins=bins,
                                  range=(hmin, hmax))

            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath + 'interactive_grade_distribution_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Grade Distribution: %s" % self._xdata.course_id
            chart = multiBarChart(name=title, height=400)
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(X1)

            extra_serie = {
                "tooltip": {
                    "y_start": "",
                    "y_end": ""
                },
                "color": xff.colors['neutral']
            }
            chart.add_serie(name="Count", y=Y1, x=X1, extra=extra_serie)
            extra_serie = {
                "tooltip": {
                    "y_start": "",
                    "y_end": ""
                },
                "color": xff.colors['institute']
            }
            chart.add_serie(name="Duration", y=Y2, x=X2, extra=extra_serie)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
コード例 #35
0
ファイル: cal_analyze.py プロジェクト: jacobbaron/gcal-stats
def plot_cal_bars(data):
    weekShow = ((data['Duration'] / np.timedelta64(1, 'h')).groupby(
        data.Calendar).resample('W').sum().unstack(level=0)).round(1)

    #xlabels
    weekNames = weekShow.set_index(
        weekShow.index.strftime("%b %d")).index.tolist()
    #mini bar names
    calNames = weekShow.columns.tolist()
    from nvd3 import multiBarChart
    from markupsafe import Markup
    chart = multiBarChart(width=1600, height=400, x_axis_format=None)
    xdata = weekNames
    extra_serie = {"tooltip": {"y_start": "You spent ", "y_end": " hours"}}
    for cal_name in weekShow:
        chart.add_serie(name=cal_name,
                        y=weekShow[cal_name].tolist(),
                        x=xdata,
                        extra=extra_serie)
    chart.buildhtml()
    plot = Markup(chart.htmlcontent)
    return plot

    # months = [g for n, g in weekShow.groupby(pd.TimeGrouper('3M'))]
    # # pdb.set_trace()
    # from matplotlib.backends.backend_pdf import PdfPages
    # #pp = PdfPages('calData.pdf')
    # F = []
    # pdb.set_trace()
    # for dmonth in months:
    #     f = Figure()
    #     dmonth.set_index(dmonth.index.strftime("%b %d")).plot(kind = "bar")

    #     monthStart = dmonth.index[0].strftime("%B %Y")
    #     monthEnd = dmonth.index[len(dmonth)-1].strftime("%B %Y")
    #     plt.title('{} - {}'.format(monthStart,monthEnd))
    #     plt.ylabel('Time (hours)')
    #     plt.gcf().subplots_adjust(bottom = 0.15)
    #     plt.close()
    #     F.append(f)
    # return f
    #    pp.savefig()
#   pp.close()

# for event in events:
#     start = event['start'].get('dateTime', event['start'].get('date'))
#     dt = datetime.fromtimestamp(rfc.tf_from_timestamp(start),Local)
#     if event['summary'].lower() == 'Arrived At work'.lower():
#         timeList.append([dt, []])
#         i = i + 1
#     if event['summary'].lower() == 'Left Work'.lower():

#         if not timeList[len(timeList)-1][1]: #means there exists a arrival time for this session
#             timeList[len(timeList)-1][1] = dt
#         else:
#             timeList.append([[],dt])
#     cond.append(event['summary'])
#     print(start, event['summary'])

# workTime = []
# totTime = timedelta(0)
# i = 1
# for session in timeList:
#     if session[0] and session[1]:
#         dur = session[1] - session[0]
#     else:
#         print(session[0])
#         print(session[1])
#         # print('start time = {0}, end time = {1}'.format(session[0].strftime("%A, %d. %B %Y %I:%M%p"),session[1].strftime("%A, %d. %B %Y %I:%M%p"))
#         dur = timedelta(0)
#     workTime.append(dur)
#     print('Session {0}: time = {1} hrs'.format(i, dur.total_seconds()/3600))
#     totTime = workTime[len(workTime) - 1] + totTime
#     i = i + 1
# print('Total work this week: {0} hrs'.format(totTime))


# if event['summary'] == 'Arrived At Work':
#             arrivalTimes.append(start)
#         if event['summary'] == 'Left Work':
#             departTimes.append(start)

# if __name__ == '__main__':
#     main()
コード例 #36
0
ファイル: Visual.py プロジェクト: Jiaza492/job-finder
from nvd3 import pieChart
from nvd3 import multiBarChart
import time
import datetime

output_file = open('Visual.html', 'w')  # Write html output file

#----------------------- Stacked Bar Chart of First MultiBarChart - Keywords in Job Title

# Title of Chart
type = "Hottest Key Words in Job Title"
# Use Multibar Chart to display in our HTML - Height, Width, Stacked, Formating X axis into date
chart = multiBarChart(name=type,
                      height=400,
                      width=1100,
                      stacked=True,
                      x_is_date=True,
                      x_axis_format="%d-%b-%Y")
# Header insert in our HTML
chart.set_containerheader("\n\n<h3>" + type + "</h3>\n\n")
# Date - X axis
xdata = [
    1416027600001, 1416227600001, 1416427600001, 1416627600001, 1416727600001
]
# Data - Y axis - Values
ydata1 = [
    0.19763513513513514, 0.1625, 0.1704225352112676, 0.20998719590268886,
    0.16584158415841585
]
# Transfer to [0, 100] percentage
ydata1 = [ydata1[i] * 100 for i in range(5)]
コード例 #37
0
ファイル: Visual.py プロジェクト: Jiaza492/JobFinder
# 6. Install nvd3#.1.12-beta: bower install nvd3#1.1.12-beta
#------------------------------------------------------------------------------------
 
from nvd3 import pieChart
from nvd3 import multiBarChart
import time
import datetime
 
output_file = open('Visual.html', 'w')      # Write html output file
 
#----------------------- Stacked Bar Chart of First MultiBarChart - Keywords in Job Title
 
# Title of Chart
type = "Hottest Key Words in Job Title"
# Use Multibar Chart to display in our HTML - Height, Width, Stacked, Formating X axis into date
chart = multiBarChart(name=type, height=400, width=1100, stacked= True, x_is_date=True, x_axis_format="%d-%b-%Y")
# Header insert in our HTML
chart.set_containerheader("\n\n<h3>" + type + "</h3>\n\n")
# Date - X axis
xdata= [1416027600001, 1416227600001, 1416427600001, 1416627600001, 1416727600001]
# Data - Y axis - Values
ydata1 = [0.19763513513513514, 0.1625, 0.1704225352112676, 0.20998719590268886, 0.16584158415841585]
# Transfer to [0, 100] percentage
ydata1 = [ydata1[i]*100 for i in range(5)]
ydata2 = [0.13429054054054054, 0.1375, 0.1323943661971831, 0.18053777208706787, 0.15594059405940594]
ydata2 = [ydata2[i]*100 for i in range(5)]
ydata3 = [0.11570945945945946, 0.1125, 0.11408450704225352, 0.10627400768245839, 0.1419141914191419]
ydata3 = [ydata3[i]*100 for i in range(5)]
ydata4 = [0.10557432432432433, 0.10000001, 0.09859154929577464, 0.09603072983354674, 0.12458745874587458]
ydata4 = [ ydata4[i]*100 for i in range(5) ]
ydata5 = [0.10050675675675676, 0.0875, 0.08873239436619719, 0.07810499359795134, 0.09735973597359736]
コード例 #38
0
for d3.js without taking away the power that d3.js gives you.

Project location : https://github.com/areski/python-nvd3
"""

from nvd3 import multiBarChart
import random
import time
import datetime

#Open File for test
output_file = open('test_multiBarChart_date.html', 'w')

type = "multiBarChart"

chart = multiBarChart(name=type, height=350, x_is_date=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")

nb_element = 100
start_time = int(time.mktime(datetime.datetime(2013, 6, 1).timetuple()) * 1000)
xdata = range(nb_element)
xdata = map(lambda x: start_time + x * 100000000, xdata)
ydata = [i + random.randint(1, 10) for i in range(nb_element)]
ydata2 = map(lambda x: x * 2, ydata)

tooltip_date = "%d %b %Y %H:%M:%S %p"
extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"},
               "date_format": tooltip_date}

chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
コード例 #39
0
    def gender(self, **kwargs):
        """
        Creates gender distribution figures.
       
        Parameters (generated during class initialization)
        ----------
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        NVD3 = kwargs.get('NVD3', False)

        ### Removes those users not having the option to fill in edX registration data.
        trim_data = self.person[(self.person.registered == 1)
                                & (self.person.user_id > 156633)]

        ### Data
        gdict = {'f': "$Female$", 'm': "$Male$", 'o': "$Other$"}
        glist = ['$Female$', '$Male$']

        ### Munge and Plot
        gender = trim_data.gender.dropna().apply(
            lambda x: gdict[x]).value_counts()
        #print gender
        certs = trim_data[trim_data.certified == 1]
        if certs.username.count() > self.mincerts:
            certs = certs.gender.dropna().apply(
                lambda x: gdict[x]).value_counts()
        else:
            certs = pd.Series(index=gender.index)

        gender = pd.concat([gender, certs],
                           join='inner',
                           axis=1,
                           keys=['$Non-Certified$', '$Certified$'])
        gender = 100. * gender / gender.sum()
        gender = gender.apply(lambda x: np.round(x, 1))

        fig = plt.figure(figsize=(12, 6))
        ax1 = fig.add_subplot(1, 1, 1)
        gender.ix[glist, :].plot(
            ax=ax1,
            kind='bar',
            color=[xff.colors['neutral'], xff.colors['institute']],
            rot=0)

        ### Plot Details
        ax1.set_xticklabels([r'%s' % x for x in glist])
        ax1.set_yticklabels(
            [r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],
            fontsize=30)
        ax1.legend(loc=2, prop={'size': 28}, frameon=False)

        ### Generalized Plotting functions
        figsavename = self.figpath + 'gender_distribution_' + self.nickname.replace(
            '.', '_')
        print figsavename
        xff.texify(fig,
                   ax1,
                   xlabel=None,
                   ylabel='Count',
                   figsavename=figsavename + '.png')

        # ### Output JSON Records
        # gender.name = 'value'
        # gender = gender.reset_index().rename(columns={'index':'label'})
        # gender.dropna().to_json(figsavename+'.json',orient='records')

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:

            'http://nvd3.org/examples/pie.html'

            X = [x.replace('$', '') for x in gender.index]
            Y1 = gender.ix[glist, '$Non-Certified$'].values
            Y2 = gender.ix[glist, '$Certified$'].values

            #----------------------------------------------------------------
            ### BAR Chart
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath + 'interactive_gender_distribution_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Gender Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = multiBarChart(name=charttype,
                                  height=350,
                                  x_axis_format="",
                                  y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(gender.ix[glist, :])

            ### Series 1
            extra_serie1 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['neutral'],
                "format": ".1f"
            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)

            ### Series 2
            extra_serie2 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['institute'],
                "format": ".1f"
            }
            chart.add_serie(name="Certificate Earners",
                            y=Y2,
                            x=X,
                            extra=extra_serie2)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

            #----------------------------------------------------------------
            ### Pie Chart
            from nvd3 import pieChart

            ### Output File
            figsavename = self.figpath + 'interactive_gender_piechart_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Gender Pie Chart: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = pieChart(name=charttype,
                             color_category='category20c',
                             height=400,
                             width=400)
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")

            extra_serie = {"tooltip": {"y_start": "", "y_end": " certified"}}

            chart.add_serie(y=Y1, x=X, extra=extra_serie)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(-10, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]
extra_serie = {"tooltip": {"y_start": "", "y_end": " Calls"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " Min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)
# ---------------------------------------

type = "multiBarChart"
chart = multiBarChart(height=400, width=800, jquery_on_ready=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 10
xdata = list(range(nb_element))
ydata = [random.randint(1, 10) for i in range(nb_element)]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "", "y_end": " call"}}
chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)
chart.buildcontent()

output_file.write(chart.htmlcontent)
# ---------------------------------------
コード例 #41
0
    def age(self, **kwargs):
        """
        Creates gender distribution figures.
       
        Parameters (generated during class initialization)
        ----------
        NVD3 = False.  If true, nvd3 interactive figure output.

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        NVD3 = kwargs.get('NVD3', False)

        ### Removes those users not having the option to fill in edX registration data.
        trim_data = self.person[(self.person.registered == 1)
                                & (self.person.user_id > 156633)]
        # Add age column from year_of_birth
        trim_data['age'] = trim_data['YoB'].apply(
            lambda x: datetime.datetime.now().year - x
            if isinstance(x, int) else None)

        age = trim_data.age.dropna()
        h, e = np.histogram(age.values, bins=9, range=(0, 90))
        age = pd.Series(data=h,
                        index=[
                            '0-9', '10-19', '20-29', '30-39', '40-49', '50-59',
                            '60-69', '70-79', '80-89'
                        ])

        certs = trim_data[trim_data.certified == 1]
        if certs.username.count() > self.mincerts:
            certs = certs.age.dropna()
            h, e = np.histogram(certs.values, bins=9, range=(0, 90))
            certs = pd.Series(data=h,
                              index=[
                                  '0-9', '10-19', '20-29', '30-39', '40-49',
                                  '50-59', '60-69', '70-79', '80-89'
                              ])
        else:
            certs = pd.Series(index=age.index)

        age = pd.concat([age, certs],
                        join='inner',
                        axis=1,
                        keys=['$Non-Certified$', '$Certified$'])
        age = 100. * age / age.sum()
        age = age.apply(lambda x: np.round(x, 1))
        #print age

        #----------------------------------------------------------------
        ### Static Matplotlib PNG
        fig = plt.figure(figsize=(12, 6))
        ax1 = fig.add_subplot(1, 1, 1)
        age.plot(
            ax=ax1,
            kind='bar',
            color=[xff.colors['neutral'], xff.colors['institute']],
            rot=40,
        )

        ### Plot Details
        ax1.set_xticklabels([r'$%s$' % x for x in age.index])
        ax1.set_yticklabels(
            [r'${0}\%$'.format("%.0f" % (y)) for y in ax1.get_yticks()],
            fontsize=30)
        ax1.legend(loc=1, prop={'size': 28}, frameon=False)

        ### Generalized Plotting functions
        figsavename = self.figpath + 'age_distribution_' + self.nickname.replace(
            '.', '_')
        print figsavename
        xff.texify(fig,
                   ax1,
                   xlabel='Age',
                   ylabel=None,
                   figsavename=figsavename + '.png')

        #----------------------------------------------------------------
        ### NVD3 Interactive http://nvd3.org/
        if NVD3:
            ### FIGURE
            from nvd3 import multiBarChart

            ### Output File
            figsavename = self.figpath + 'interactive_age_distribution_' + self.nickname + '.html'
            output_file = open(figsavename, 'w')
            print figsavename

            title = "Age Distribution: %s" % self._xd.course_id
            charttype = 'multiBarChart'
            chart = multiBarChart(name=charttype,
                                  height=350,
                                  x_axis_format="",
                                  y_axis_format=".1f")
            chart.set_containerheader("\n\n<h2>" + title + "</h2>\n\n")
            nb_element = len(age)
            X = age.index  #list(range(nb_element))
            Y1 = age['$Non-Certified$'].values
            Y2 = age['$Certified$'].values

            ### Series 1
            extra_serie1 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['neutral'],
                "format": ".1f"
            }
            chart.add_serie(name="Participants", y=Y1, x=X, extra=extra_serie1)

            ### Series 2
            extra_serie2 = {
                "tooltip": {
                    "y_start": "",
                    "y_end": "%"
                },
                "color": xff.colors['institute'],
                "format": ".1f"
            }
            chart.add_serie(name="Certificate Earners",
                            y=Y2,
                            x=X,
                            extra=extra_serie2)

            ### Final Output
            chart.buildhtml()
            output_file.write(chart.htmlcontent)

            #---------------------------------------

            #close Html file
            output_file.close()

        return None
for d3.js without taking away the power that d3.js gives you.

Project location : https://github.com/areski/python-nvd3
"""

from nvd3 import multiBarChart
import random
import time
import datetime

# Open File for test
output_file = open('test_multiBarChart_date.html', 'w')

type = "multiBarChart"

chart = multiBarChart(name=type, height=350, x_is_date=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")

nb_element = 100
start_time = int(time.mktime(datetime.datetime(2013, 6, 1).timetuple()) * 1000)
xdata = range(nb_element)
xdata = map(lambda x: start_time + x * 100000000, xdata)
ydata = [i + random.randint(1, 10) for i in range(nb_element)]
ydata2 = map(lambda x: x * 2, ydata)

tooltip_date = "%d %b %Y %H:%M:%S %p"
extra_serie = {
    "tooltip": {
        "y_start": "There are ",
        "y_end": " calls"
    },
コード例 #43
0
def graph_ecotype():
    key = 'organsim'
    key2 = "multigraph"
    requete="SELECT  "\
        "  distinct(organism.organism_name), "\
        "  ecotype.ecotype_name,  "\
        "  sample_source.project_id  "\
        " FROM   "\
        "  chips.sample_source,  "\
        "  chips.organism,  "\
        "  chips.ecotype  "\
        "WHERE   "\
        "  sample_source.ecotype_id = ecotype.ecotype_id AND  "\
        "  organism.organism_id = sample_source.organism_id  "\
        "order by ecotype_name,organism.organism_name;  "
    r, data = getdata(requete)
    dat = pd.DataFrame(data)
    dat2 = pd.crosstab(dat[0], dat[1])

    #test du plus lon

    dat2 = pd.crosstab(dat[0], dat[1])
    dat2 = pd.DataFrame(np.transpose(dat2))

    #r,data=getdata(requete)

    #if len(data)>0:
    #    for i in range(0,len(data)):
    #        xdata.append(data[i][0])
    #        ydata1.append(int(data[i][1]))
    split = dict(np.transpose(dat2).sum())
    list1 = []
    list2 = []
    for element in split.keys():
        if split[element] > 1:
            list1.append(element)
        else:
            list2.append(element)

    from nvd3 import multiBarChart
    chart1 = multiBarChart(name=key2,
                           width=800,
                           height=800,
                           x_axis_format=None)
    #text_white="chart.stacked(true);"
    #chart1.add_chart_extras(text_white)
    chart2 = multiBarChart(width=800, height=800, x_axis_format=None)
    xdata = list(dat2.index)  #['one', 'two', 'three', 'four']
    #ydata1 = [6, 12, 9, 16]
    serie_lab = list(dat2.columns)
    for ele in range(0, len(serie_lab)):
        if ele != 1:
            chart1.add_serie(name=serie_lab[ele],
                             y=list(dat2.loc[list1, serie_lab[ele]]),
                             x=list1)
        #chart2.add_serie(name=serie_lab[ele], y=list(dat2.loc[list2,serie_lab[ele]]), x=list1)
    chart1.buildhtml()
    text = chart1.htmlcontent
    argument1 = "var chart = nv.models.multiBarChart();\n\n"
    argument2 = "var chart" + key + " = nv.models.multiBarChart();\n\n \n\n"
    text = text.replace(argument1, argument2)
    text = text.replace("chart.", "chart" + key + ".")

    argument7 = """});\n        var datum ="""
    argument8 = """});\n  chart""" + key + """.legendPosition("right");\n      var datum ="""
    text = text.replace(argument7, argument8)

    text = text.replace(".call(chart);", ".call(chart" + key + ");")
    text = text.replace(
        "</script>",
        "$('#multigraph1 .nv-controlsWrap .nv-series:eq(0)').addClass('nv-disabled');\n </script>"
    )
    argument3 = "nv.addGraph(function() {\n"
    argument4 = "function rungraph(){ \n nv.addGraph(function() {\n"
    text = text.replace(argument3, argument4)
    argument5 = "</script>"
    argument6 = "};\n rungraph(); \n alert(); </script>"
    text = text.replace(argument5, argument6)
    return text
コード例 #44
0
import os
import csv
from nvd3 import multiBarChart

output = open('static/index.html', 'w')
input_data = list(csv.reader(open('dateCrimeOutput.txt', 'rb'),
                             delimiter='\t'))
chart = multiBarChart(name='multiBarChart',
                      height=800,
                      width=1800,
                      margin_bottom=300,
                      margin_top=40,
                      margin_left=60,
                      margin_right=60)
crimes = []
for row in input_data:
    crimes.append([row[0], int(row[1]), int(row[2])])
crimes = sorted(crimes, key=lambda crimes: crimes[1], reverse=True)
current_year = None
i = 0
for crime in crimes:
    if crime[1] == current_year:
        globals()['xdata%s' % i].append(crime[0])
        globals()['ydata%s' % i].append(crime[2])
    else:
        current_year = crime[1]
        i = i + 1
        globals()['year%s' % i] = str(crime[1])
        globals()['ydata%s' % i] = []
        globals()['xdata%s' % i] = []
        globals()['ydata%s' % i].append(crime[2])
コード例 #45
0
ファイル: psit.py プロジェクト: opor-jitpanu/project_psit
def main():
    mo = ['JANUARY','FEBRUARY','MARCH','APRIL','MAY','JUNE',\
          'JULY','AUGUST','SEPTEMBER','OCTOBER','NOVEMBER','DECEMBER']
    ######year 2014#####
    list_inj = []
    list_fata = []
    list_city = []
    
    lis = year_2014_01()
    fata = lis[0]
    inj = lis[1]

    list_inj.append(inj)
    list_fata.append(fata)


    
    lis = year_2014_02()
    fata = lis[0]
    inj = lis[1]

    list_inj.append(inj)
    list_fata.append(fata)

    
    lis = year_2014_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)

    
    lis = year_2014_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    lis = year_2014_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2014.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()
    ##end year 2014##

    #####year 2013#####
    list_inj = []
    list_fata = []
    lis = year_2013_01()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_02()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2013_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2013.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()
    ##end year 2013##

    #####year 2012#####
    list_inj = []
    list_fata = []
    lis = year_2012_01()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_02()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2012_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2012.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()
    
    ######year 2011#####
    list_inj = []
    list_fata = []
    lis = year_2011_01()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_02()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2011_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2011.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()
    ###end year 2011###
    #####year 2010#####
    list_inj = []
    list_fata = []
    lis = year_2010_01()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_02()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2010_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2010.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()

    #######year 2009########
    list_inj = []
    list_fata = []
    lis = year_2009_01()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_02()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2009_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2009.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()

    
    ####year 2008#####
    list_inj = []
    list_fata = []
    lis = year_2008_01()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_02()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_03()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_04()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_05()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_06()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_07()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_08()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_09()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_10()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_11()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    lis = year_2008_12()
    fata = lis[0]
    inj = lis[1]
    list_inj.append(inj)
    list_fata.append(fata)
    
    chart = multiBarChart(width=500, height=400, x_axis_format=None)
    xdata = mo
    ydata1 = list_inj
    ydata2 = list_fata

    chart.add_serie(name="INJURED", y=ydata1, x=xdata)
    chart.add_serie(name="FATALITIES", y=ydata2, x=xdata)
    chart.buildhtml()
    
    text_file = open("year_2008.html", "w")
    text_file.write(chart.htmlcontent)
    text_file.close()


    ########################################################
    ########################################################
    ########################################################
                        ####plot map####

    ######year 2014#
    list_la = []
    list_long = []
    new_la = []
    new_long = []

    lis = la_2014()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)

    lis = la_2013()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)

    lis = la_2012()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)

    lis = la_2011()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)

    lis = la_2010()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)

    lis = la_2009()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)

    lis = la_2008()
    la = lis[1]
    long = lis[2]
    list_la.append(la)
    list_long.append(long)
    
    for i in list_la:
        num = float(i)
        new_la.append(num)
    for j in list_long:
        num2 = float(j)
        new_long.append(num2)
        
    mymap = pygmaps.maps(new_la[0], new_long[0], 14)
     
    path = [(new_la[0], new_long[0]),
            (new_la[1], new_long[1]),
            (new_la[2], new_long[2]),
            (new_la[3], new_long[3]),
            (new_la[4], new_long[4]),
            (new_la[5], new_long[5]),
            (new_la[6], new_long[6]),]
 
    for point in path:
        mymap.addpoint(point[0], point[1])
 

    mymap.draw('./map_all.html')