def drawing_pie(start_date, end_date):
    sentiment_dictionary = get_sentiment_dates(start_date, end_date)

    sentiment_array = util.total_sentiment_array(sentiment_dictionary)

    positive_count = sentiment_array[0]
    negative_count = sentiment_array[1]
    neutral_count = sentiment_array[2]

    sentiment = ''
    if positive_count > negative_count or positive_count > neutral_count:
        sentiment = 'Sentiment is Positive'
    elif negative_count > positive_count or negative_count > neutral_count:
        sentiment = 'Sentiment is Negative'
    elif neutral_count > positive_count or neutral_count > negative_count:
        sentiment = 'Sentiment is Neutral'
    elif positive_count == neutral_count and positive_count > negative_count:
        sentiment = 'Sentiment is Positive'
    elif negative_count == neutral_count and negative_count > positive_count:
        sentiment = 'Sentiment is Negative'

    labels = ['Positive', 'Negative', 'Neutral']
    colors = ['blue', 'green', 'red']
    explode = (0, 0, 0)

    plt.pie(sentiment_array, explode=explode, labels=labels, colors=colors,
            autopct='%1.1f%%', shadow=True, startangle=90)

    plt.axis('equal')

    plt.title(sentiment)

    plt.show()

    return
def plotGenomicregions(GPcount, name):
    """
    :param GPcount: is a list of tuples [(region, size),....()]
    :return:
    """
    """ Now we produce some pie charts """

    gr = ['tss', 'intergenic', 'intron', 'exon', 'upstream']
    size = [0, 0, 0, 0, 0]
    for a, b in GPcount:
        if a == 'tss':
            size[0] = b
        if a == 'intergenic':
            size[1] = b
        if a == 'intron':
            size[2] = b
        if a == 'exon':
            size[3] = b
        if a == 'upstream':
            size[4] = b
    colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'cyan']
    explode = (0.1, 0, 0, 0, 0)  # only "explode" the 2nd slice
    plt.pie(size, explode=explode, labels=gr, colors=colors,
            autopct='%1.1f%%', shadow=True, startangle=90)
    # Set aspect ratio to be equal so that pie is drawn as a circle.
    #plt.legend(['tss', 'intergenic', 'intron', 'exon', 'upstream'], loc='upper left')
    plt.axis('equal')
    plt.savefig('/ps/imt/e/20141009_AG_Bauer_peeyush_re_analysis/further_analysis/plots/' + name + '.svg')
    plt.clf()
Esempio n. 3
0
    def display_PER(self):

        number_of_pkts = len(self.pcap_file)
        retransmission_pkts = 0

        for pkt in self.pcap_file:

            if (pkt[Dot11].FCfield & 0x8) != 0:
                retransmission_pkts += 1

        ans = (retransmission_pkts / number_of_pkts)*100
        ans = float("%.2f" % ans)
        labels = ['Standard packets', 'Retransmitted packets']
        sizes = [100.0 - ans,ans]


        colors = ['g', 'firebrick']

        # Make a pie graph
        plt.clf()
        plt.figure(num=1, figsize=(8, 6))
        plt.axes(aspect=1)
        plt.suptitle('Retransmitted packet', fontsize=14, fontweight='bold')
        plt.rcParams.update({'font.size': 13})
        plt.pie(sizes, labels=labels, autopct='%.2f%%', startangle=60, colors=colors, pctdistance=0.7, labeldistance=1.2)

        plt.show()
def comparison_pie_plot(path, data, txt):
    """
    Plots a pie chart comparison of the # of times each AD found
    the highest best/average final solution for all simulations
    """
    # The slices will be ordered and plotted counter-clockwise.

    unzipped_data = list(zip(*data))
    num_sims = len(unzipped_data)
    sizes = [0] * len(data)
    for simulation_data in unzipped_data:
        m = max(simulation_data)
        max_indexes = [i for i, j in enumerate(simulation_data) if j == m]
        for i in max_indexes:
            sizes[i] += 1

    # percentages
    for i in range(len(sizes)):
        sizes[i] = round((sizes[i] / num_sims) * 100)

    # "explode" all slices
    explode = [0.1] * len(data)

    plt.figure()
    plt.title("Comparison of the # of times each AD found the highest " + txt + " final solution for all simulations")

    plt.pie(sizes, explode=tuple(explode), labels=AD_labels, colors=AD_color, autopct='%1.1f%%', shadow=True)

    plt.axis('equal')  # Set aspect ratio to be equal so that pie is drawn as a circle.
    plt.savefig(path + "/pie_" + txt + ".png", bbox_inches='tight')
    plt.close()

    return
def plot_percent_mentions(tweets, gop = False, save_to = None):
  '''
  Plots the percent mentions of each candidate (filtered for party)
  Used for Task 3.
  ''' 

  percents = tweets.get_percent_mentions(gop)

  candidates = [] 
  mentions = [] 
  for c, ment in percents:
    if c == "other": 
      other_v = ment 
    else:   
      candidates.append(CANDIDATE_NAMES[c[:-1]])
      mentions.append(ment)
  candidates.append("other")
  mentions.append(other_v)

  fig = plt.figure(figsize = (FIGWIDTH, FIGHEIGHT)) 

  plt.pie(mentions, labels = candidates, autopct='%1.1f%%')
  if gop: 
    plt.title("Percent of Mentions per GOP candidate")
  else: 
    plt.title("Percent of Mentions per candidate")
 
  plt.show() 
  if save_to: 
    fig.savefig(save_to)
Esempio n. 6
0
def printdata(projects, graph):
    print "************************************************************************"
    print
    print
    labels = []
    sizes = []
    explode = []
    timeSheetHours = 0
    for project in projects:
        timeSheetHours = timeSheetHours + projects[project].totalhours
        labels.append(project)
        sizes.append(projects[project].totalhours)
        explode.append(0.025)
        print(Fore.RED + "%s (%s)" % (project, str(projects[project].totalhours)) + Fore.RESET)
        for activity in projects[project].activities:
            print(Fore.CYAN + "   - %s (%s)" % (activity, str(projects[project].activities[activity].totalhours)) + Fore.RESET)
        print
    print(Fore.RED + "Total number of hours on these timesheets: " + str(timeSheetHours) + Fore.RESET)
    print
    print "************************************************************************"
    if graph:
        colors = ('b', 'g', 'r', 'c', 'm', 'y')
        plt.pie(sizes, explode=explode, labeldistance=1.2, pctdistance=1.1, labels=labels, colors=colors, autopct='%1.1f%%')
        plt.axis('equal')
        plt.show()
Esempio n. 7
0
    def display_channel_efficiency(self):

        size = 0

        start_time = self.pcap_file[0].time
        end_time = self.pcap_file[len(self.pcap_file) - 1].time

        duration = (end_time - start_time)/1000

        for i in range(len(self.pcap_file) - 1):
            size += len(self.pcap_file[i])
        ans = (((size * 8) / duration) / BW_STANDARD_WIFI) * 100
        ans = float("%.2f" % ans)
        labels = ['utilized', 'unutilized']
        sizes = [ans, 100.0 - ans]
        colors = ['g', 'r']

        # Make a pie graph
        plt.clf()
        plt.figure(num=1, figsize=(8, 6))
        plt.axes(aspect=1)
        plt.suptitle('Channel efficiency', fontsize=14, fontweight='bold')
        plt.title("Bits/s: " + str(float("%.2f" % ((size*8)/duration))),fontsize = 12)
        plt.rcParams.update({'font.size': 17})
        plt.pie(sizes, labels=labels, autopct='%.2f%%', startangle=60, colors=colors, pctdistance=0.7, labeldistance=1.2)

        plt.show()
def main():
  ## Open the file with read only permit
  f = open(filepath + alertfilename)
  ## Read the first line 
  line = f.readline()
  ## If the file is not empty keep reading line one at a time
  ## till the file is empty
  while line:
      if "User IP:" in line:
        ipquery(line[9:-1])
      line = f.readline()
  f.close()
  
  ## Count the unique IP
  ip_data = Counter(ips)
  ## Count the unique countries
  country_data = Counter(countries)
  ## Find the index of the largest entry to explode on chart
  indx = country_data.values().index(max(country_data.values()))
  explode = [0] * len(country_data.values())
  explode[indx] = 0.1
  
  ## Draw the chart
  a = np.random.random(20)
  cs = cm.Set1(np.arange(20)/20.)
  plt.pie(country_data.values(), explode=explode, labels=country_data.keys(), colors=cs, autopct='%1.1f%%', startangle=90)
  plt.axis('equal')
  plt.show()
Esempio n. 9
0
def analyzeData(db):
    # Total calls, incoming, outgoing (and percents). Times to/from liz and percentage.
    cursor = db.cursor()
    
    numCalls = cursor.execute('''SELECT Count(*) FROM calls''').fetchone()[0]
    print numCalls, "calls from May to July 2014."
    
    numIncoming = cursor.execute('''SELECT Count(*) FROM calls WHERE incoming=1''').fetchone()[0]
    print numIncoming, "incoming calls. (" + str((numIncoming*100.0)/numCalls) + "%)"
    numOutgoing = cursor.execute('''SELECT Count(*) FROM calls WHERE incoming=0''').fetchone()[0]
    print numOutgoing, "outgoing calls. (" + str((numOutgoing*100.0)/numCalls) + "%)"
    # Display the info in a pie chart
    labels = 'Incoming Calls', 'Outgoing Calls'
    values = [numIncoming, numOutgoing]
    colors = ['orange', 'seagreen']
    plt.pie(values, labels=labels, colors=colors, autopct='%1.1f%%')
    plt.axis('equal')
    plt.show()
    
    numLiz = cursor.execute('''SELECT Count(*) FROM calls WHERE phone_number='630-380-4152';
            ''').fetchone()[0]
    percentLiz = (numLiz*100.0)/numCalls
    print numLiz, "calls to/from Liz. (" + str(percentLiz) + "%)"
    # Display the info in a pie chart
    labels = 'Liz', 'Others'
    sizes = [int(percentLiz), 100 - int(percentLiz)]
    colors = ['turquoise', 'gold']
    plt.pie(sizes, colors=colors, labels=labels, autopct='%1.1f%%')
    plt.axis('equal')
    plt.show()

    return
Esempio n. 10
0
def GraficaPastel():
	import matplotlib.pyplot as plt
	import numpy as np
	
	datos=int(input("Cuantos datos ingresaras: "))
	impr=[0]*datos
	vol=[0]*datos
	expl=[0]*datos
	
	for x in range(0,datos):
		impr[x]=(input("Nombre: "))
		vol[x]=(int(input("Numero: ")))
	
	mayor=0
	for x in range(0,datos):
		if vol[x] > mayor:
			mayor = vol[x]
	
	for x in range(0,datos):
		if vol[x] == mayor:
			expl[x] = 0.05
	
	
	
	plt.pie(vol, explode=expl, labels=impr, autopct='%1.1f%%', shadow=True)
	plt.title("Pastel", bbox={"facecolor":"0.8", "pad":5})
	plt.legend()
	plt.show()
Esempio n. 11
0
    def plotPieChart(self, title=None, cmap_name='Pastel2'):
        if sys.hexversion >= 0x02700000:
            self.fig.set_tight_layout(True)

        # Generate plot data
        labels, ydata = self._getPlotData()
        totalobjects = float(np.sum(ydata))
        fracs = [ynum / totalobjects for ynum in ydata]

        explode = np.zeros(len(fracs))  # non zero makes the slices come out of the pie

        # plot pie chart
        cmap = plt.cm.get_cmap(cmap_name)
        colors = cmap(np.linspace(0., 0.9, len(fracs)))
        plt.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=False, startangle=90,
                colors=colors)

        # generate plot / axis labels
        for axis in self.ax.get_xticklabels():
            axis.set_fontsize(self.xticksize)

        if self.unit is None:  # NOTE this is hacked in so it only works with DataPerParameterClass
            self.unit = self._getParLabelAndUnit(self._planetProperty)[1]  # use the default unit defined in this class
        self._yaxis_unit = self.unit

        if title is None:
            title = 'Planet {0} Bins'.format(self._gen_label(self._planetProperty, self.unit))  # NOTE not always planet

        plt.title(title)
        plt.xlim(-1.5, 1.5)
Esempio n. 12
0
def plot_educationLevel(df):
    """
    Function takes dataframe as input,
    plot a pie of

    Argument
    ========
    DataFrame

    """

    degree=degreeDict(df)
    bach=degree['Bachelor']
    master=degree['Master']
    others=degree['High School or others non-degree']
    labels = 'At least \n a Bachelor degree', 'At least\n   A Master \n degree','Others:\nHigh school \nDiploma or \nSome experiences '
    fracs = [bach, master, others]
    plt.figure(figsize=(12,8))
    explode = (0.05, 0.05, 0.05)
    colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
    plt.pie(fracs,explode=explode, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
    plt.axis('equal')
    plt.legend(labels,loc="lower right")
    plt.title('Minimum Degree Requirement', fontsize=20)
    plt.show()
Esempio n. 13
0
def create_pie_chart(data, title, filename, cutoff=0.01, verbose=False):
    """Create a pie chart from the given data

    Params:
    data- a collections.Counter where the keys should be the labels to
        the graph

    """
    total = float(sum(data.values()))
    frac_labels = []
    other_count = 0
    # compute the fraction for each label
    for cnt in data.keys():
        fraction = float(data[cnt]) / total
        if verbose:
            print "{}: {}".format(cnt, fraction)
        # if this slice is too small, just add it to other small
        # totals and display them together
        if fraction < cutoff:
            other_count += data[cnt]
            continue
        frac_labels.append((fraction, cnt))
    if other_count > 0:
        frac_labels.append((float(other_count) / total, "Other"))
    frac_labels.sort(key=lambda entry: entry[1])
    fractions, labels = zip(*frac_labels)
    plt.figure()
    plt.pie(fractions, labels=labels, autopct='%1.1f%%',
            colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'))
    plt.title(title)
    plt.savefig(filename, fmt='pdf')
def plot_visit_duration_dist(page_info, course, style='pie',
                             include_subpages=True):
    dict_to_plot = visit_duration_dist(page_info, course, include_subpages)
    y = []
    my_labels = []
    for num, key in enumerate(sorted(dict_to_plot.keys())):
        # disregard entries below 1%
        if float(dict_to_plot[key]) / sum(dict_to_plot.values()) < 0.01:
            continue
        y.append(dict_to_plot[key])
        if 'pie' == style:
            my_labels.append(key.replace(
                '_', '') + ' [' + str(int(y[num] / 60 / 60)) + 'h ' + str(
                int(100 * round(float(dict_to_plot[key]) / sum(
                    dict_to_plot.values()), 2))) + '%]')
        elif 'bar' == style:
            my_labels.append(key.replace(
                'December_', 'Dec').replace(
                'April_', 'Apr').replace(
                '20', '') + '\n' + str(
                int(100 * round(float(dict_to_plot[key]) / sum(
                    dict_to_plot.values()), 2))) + '%')
    y = np.asarray(y)
    if 'pie' == style:
        plt.pie(y, labels=my_labels, startangle=90)
    elif 'bar' == style:
        plt.bar(range(len(y)), y / 60 / 60, align='center',
                color=create_RGB_list(len(y)))
        plt.gca().set_xticks(range(len(y)))
        plt.gca().set_xticklabels(my_labels)
        plt.ylabel('Total pageview time in hours')
    plt.title(course + ' - Total pageview time per exam')
Esempio n. 15
0
def plot_NA_ratio_features(dataset, feature_names, missing_value_string='nan'):

	y, x = dataset.shape
	ind = np.zeros((x, 1)).reshape(1, x)

	for j in range(y):
		for i in range(x):
			# print str(dataset[j, i])
			if missing_value_string == str(dataset[j, i]):
				ind[0, i] += 1

	ind = (ind/y*100)


	labels = 'NA', ''
	colors = ['yellowgreen', 'lightcoral']
	explode = (0, 0)
	plt.rcParams.update({'font.size': 8})
	plt.suptitle("NA ration", fontsize=16)

	for i in range(x):
		ax = plt.subplot(5, 5, i+1)
		ax.set_title(feature_names[i])
		sizes = [ind[0, i], 100-ind[0, i]]
		plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%')
		# autopct permits to add the value of the part in chart
		plt.axis('equal')

	plt.show()
Esempio n. 16
0
    def displayIncomeByGender():
        from FileValidation import Validation
        a = Validation()
        data_list = a.theFile
        list_size = len(data_list)
        incomes = []
        female_income = 0
        male_income = 0

        for element in range(0, list_size):
            if data_list[element][1] == "F":
                female_income += int(data_list[element][5])
            elif data_list[element][1] == "M":
                male_income += int(data_list[element][5])

        incomes.append(female_income)
        incomes.append(male_income)

        plt.title("Male and Female Income Ratio")
        labels = 'Female Income', 'Male Income'
        sizes = incomes
        colors = ['pink', 'blue']
        plt.pie(sizes, labels=labels, colors=colors,
        autopct='%1.1f%%', shadow=True, startangle=90)
        plt.axis('equal')
        plt.show()
def make_chart_pie_chart():

    plt.pie([0.95, 0.05], labels=["Uses pie charts", "Knows better"])

    # make sure pie is a circle and not an oval
    plt.axis("equal")
    plt.show()
def createSingleObjectPieChart(objectOrientationDict,outputPath,objectType):
    userInput=''
    orientationList = objectOrientationDict[objectType]
    labels = 'Left - ' + str(orientationList[0]), 'Right - ' + str(orientationList[1]), 'Frontal - ' + str(orientationList[2]), 'Rear - ' + str(orientationList[3]), 'Unspecified - ' + str(orientationList[4])
    sizes = objectOrientationDict[objectType]
    colors = ['yellowgreen', 'gold', 'lightskyblue', 'orange','red']
    plt.subplots_adjust(top=0.85)
    plt.title('The Distribution of ' + str(sum(orientationList)) + ' '+ objectType[0].upper() + objectType[1:] + ' Object by Orientation.',fontsize=16, fontweight='bold')
    plt.pie(sizes, labels=labels, colors=colors,
            autopct='%1.1f%%', shadow=True, startangle=45)
    # Set aspect ratio to be equal so that pie is drawn as a circle.
    plt.axis('equal')
    while userInput is not 'y' or 'n':
        userInput = raw_input("Would you like to save the figure? (y/n) ")
        userInput = userInput.lower()
        if userInput == 'y':
            path = os.path.abspath(outputPath)
            filename = 'graphObjectOrientation_Piechart.png'
            fullpath = os.path.join(path, filename)
            plt.savefig(fullpath)
            break
        elif userInput == 'n':
            break
        else:
            print "Please answer y or n. " '\n'
    plt.show()
Esempio n. 19
0
    def displayAgeGroupIncome():
        from FileValidation import Validation
        a = Validation()
        data_list = a.theFile
        list_size = len(data_list)
        incomes = []
        under_30_income = 0
        between30_50_income = 0
        above50_income = 0

        for element in range(0, list_size):
            if int(data_list[element][2]) > 0\
            and int(data_list[element][2]) <= 30:
               under_30_income += int(data_list[element][5])
            elif int(data_list[element][2]) > 30\
            and int(data_list[element][2]) <= 50:
                between30_50_income += int(data_list[element][5])
            elif int(data_list[element][2]) > 50:
                above50_income += int(data_list[element][5])

        incomes.append(under_30_income)
        incomes.append(between30_50_income)
        incomes.append(above50_income)

        plt.title("Age Group and Income Ratio")
        labels = 'Age under 30', 'Age between 31-50', 'Age above 50'
        sizes = incomes
        colors = ['Blue', 'Green', 'Orange']
        plt.pie(sizes, labels=labels, colors=colors,
        autopct='%1.1f%%', shadow=True, startangle=90)
        plt.axis('equal')
        plt.show()
def generate_piechart(TPdata, key, dictionary):
    """generates a pie chart about a key in the dataset using translation dictionary"""

    counts = defaultdict(int)  # empty dictionary

    for TP in TPdata:
        counts[TP[key]] += 1

    logging.debug("extracted counts: [%s]", str(counts) )

    fig1 = plt.figure(figsize=(8,8)) ## makes sure that there is no squeezing of the round pie
    plt.axis('equal')

    values = [value for key, value in counts.items()]
    labels = counts.keys()

    if dictionary:
        labels = translate_labels(labels, dictionary)

    labels = add_sum_to_labels(values, labels)

    plt.pie(values, explode=None, \
                labels=labels, colors=None, autopct=None, pctdistance=0, \
                shadow=False, labeldistance=1.1, hold=None)

    plt.show()
Esempio n. 21
0
    def pie_chart_secondary(self, field, period=None, dst_fname=None, dpi=200):
        """ 显示顶层分类下的子类别的时间饼图,人这个图里可以看到一段时间内, 某个主类别下面的任务的时间分配情况

        :param field: 顶层类别名称
        :param period: 统计周期,tuple 类型数据,其中 interval[0] 表示开始的日期,interval[1] 表示结束日期
        :param dst_fname: 目标文件名,如果为空,则直接在输出的文件名后加上 ‘_pie_chart.png’ 后缀
        :param dpi: 图片质量
        """

        if not self.cached:
            self._process_data()

        if field not in self.data_raw['List Name'].unique():
            print('error: field %s is not an top level category.')
            return

        # select data from interval
        if not period:
            period = (self.start_day, self.end_day)
        data = self.data_raw.loc[period[0]: period[1]]
        tag_list = data.groupby(['List Name', 'Tag']).sum()

        plt.clf()
        _labels = lambda values: [v.decode('utf-8') for v in values]
        title = u'精力分配: %s [%s - %s]' % (field.decode('utf-8'), period[0], period[1])
        plt.title(title)
        plt.axis('equal')
        plt.pie(tag_list.loc[field]['Duration'].values,
                labels=_labels(tag_list.loc[field].index.values),
                autopct='%1.0f%%')

        if not dst_fname:
            dst_fname = self.datafile + '_pie_chart_sec.png'
        plt.savefig(dst_fname, dpi=dpi)
Esempio n. 22
0
def plot_pie(df, name):
    """ plot a pie chart showing composition of different restaurants, return 1 if succeed """
    # Get restaurant count group by description in descending order
    ranking = df.groupby('DESCRIPTION').count().sort('CAMIS', ascending=False)
    n = ranking.sum()[0] - ranking.ix['Other'][0]
    # Get top 10 descriptions and their corresponding counts
    other = n - ranking[:10].sum()[0]
    labels = list(ranking.index[:10])
    try:
        labels.remove('Other')
    except ValueError:
        pass
    sizes = []
    for label in labels:
        sizes.append(ranking.ix[label][0])
    labels = [x.decode('utf8').encode('ascii', 'replace') for x in labels]
    labels.append('Other')
    sizes.append(other)
        
    cm = plt.get_cmap('gist_rainbow')
    colors = [cm(x) for x in np.arange(0, 1, 1./len(labels))]

    plt.figure()
    plt.pie(sizes, labels=labels, colors = colors, autopct='%1.1f%%', shadow=True, startangle=90)
    plt.title('Percentage of Different Restaurants ({})'.format(name))
    plt.axis('equal')
    plt.savefig('rest_pie_{}.png'.format(name))
    return 1
Esempio n. 23
0
def pie_graph(conn, query, output, title='', lower=0, log=False):
	labels = []
	sizes = []

	res = query_db(conn, query)
	# Sort so the graph doesn't look like complete shit.
	res = sorted(res, key=lambda tup: tup[1])
	for row in res:
		if row[1] > lower:
			labels.append(row[0])
			if log:
				sizes.append(math.log(row[1]))
			else:
				sizes.append(row[1])
	# Normalize.
	norm = [float(i)/sum(sizes) for i in sizes]

	plt.pie(norm,
			labels=labels,
			shadow=True,
			startangle=90,
	)
	plt.figtext(.1,.03,'{}\n{} UTC'.format(site,generation_time))
	plt.axis('equal')
	plt.legend()
	plt.title(title)
	plt.savefig(output)
	plt.close()
Esempio n. 24
0
def plotResults(red_wins, black_wins, tie):

    # Adjusting the plot results to not show 0%`s
    def make_autopct(values):
        def my_autopct(pct):
            if pct == 0:
                return ""
            else:
                return '{p:.1f}% '.format(p=pct)

        return my_autopct

    # Setting up plot variables
    labels = ['Red Wins', 'Black Wins', 'Ties']
    sizes = [red_wins, black_wins, tie]
    colors = ['yellowgreen', 'gold', 'lightskyblue']
    explode = (0.1, 0, 0)

    plt.pie(sizes, colors=colors, explode=explode, labels=labels, autopct=make_autopct(sizes), shadow=True,
            startangle=70)
    plt.axis('equal')
    plt.tight_layout()
    plt.show()
    print "number of red wins ", red_wins
    print "number of black wins ", black_wins
    print "number of ties ", tie
Esempio n. 25
0
    def plot_single_piechart(self, cluster_no, labels, pdf):
       cluster_label_dict = {}

       for label in labels:
           if label not in cluster_label_dict:
               cluster_label_dict[label] = 1
           else:
               cluster_label_dict[label] += 1
       distinct_labels = []
       label_counts = []
       colors = []
       cmap = self.get_cmap(30)
       i = 0
       for label,value in cluster_label_dict.iteritems():
           colors.append(cmap(i))
           distinct_labels.append(label)
           label_counts.append(value)
           i = i+1
       matplotlib.rcParams['font.size'] = 5

       plt.figure(figsize=(8,8))
       plt.pie(label_counts, explode=None, labels=distinct_labels, colors=colors,
       autopct='%1.1f%%', shadow=True, startangle=90)
       # Set aspect ratio to be equal so that pie is drawn as a circle.
       plt.axis('equal')
       plt.suptitle("Cluster no " + str(cluster_no) + "\nNumber of docs in cluster: " + str(len(labels)),fontsize=10)
       pdf.savefig()
       plt.close()
Esempio n. 26
0
def makePieChart(bigList):
    streetNameList = []
    bikeSpaceList = []
    x = 0
    ##bigList = readBikeData.GatherData('rows.json')
    for i in range(len(bigList)):
        streetName = bigList[i][10].lower()
        bikeSpaceInt = int(bigList[i][12])
        if streetName in streetNameList:
            ndx = streetNameList.index(streetName)
            bikeSpaceList[ndx] += bikeSpaceInt
        else:
            streetNameList.append(streetName)
            bikeSpaceList.append(bikeSpaceInt)
    bikeSpaceSum = sum(bikeSpaceList)

    ##I omited any area that was less then 1% of the total bike space to get a cleaner pie chart
    while x < len(bikeSpaceList):
        if(bikeSpaceList[x] < (bikeSpaceSum * .01) and x >= 0):
            del bikeSpaceList[x]
            del streetNameList[x]
            x-=1

        else:
            x+=1

    plt.axis("equal")
    plt.pie(bikeSpaceList, labels = streetNameList, autopct = "%1.1f%%", shadow = False)
    plt.title("Bike Space to Street Name Distribution")
    plt.show()
def drawing_pie(start_date, end_date):
    p_count=0
    n_count=0
    neu_count=0
    sentiment = get_sentiment_dates(start_date,end_date)
    for semt in sentiment[0].values():
        p_count+=semt
    for semt in sentiment[1].values():
        n_count+=semt
    for semt in sentiment[2].values():
        neu_count+=semt

    print p_count
    print n_count
    print neu_count
    labels = 'Positive','Negative','Neutral'
    sizes = [p_count,n_count,neu_count]
    colors = ['green', 'red', 'yellow']
    explode = (0, 0.1, 0) # only "explode" the 2nd slice

    plt.pie(sizes, explode=explode, labels=labels, colors=colors,
            autopct='%1.1f%%', shadow=True, startangle=90)
    plt.axis('equal')
    plt.title('Sentiment is Positive')

    plt.show()
    return
Esempio n. 28
0
def pieplot(data, total, min, stitle): #Create a pie plot... mmm, pie
	import matplotlib.pyplot as plt
	labels=[]
	sizes=[]
	other=0
	if total is None: #Calc total if not given
		total=0
		for cat in data:
			total+=cat[0]
	for cat in data: #Convert values to a percentage of total, separate smaller categories
		cat[0]=cat[0]/total*100
		if cat[0]>min:
			labels.append(cat[1])
			sizes.append(cat[0])
		else:
			other+=cat[0]
	if other>0.1: #Include the rest if it's significant
		sizes.append(other)
		labels.append("Other")
	# The slices will be ordered and plotted counter-clockwise.
	colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
	#explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice # But I don't wanna explode...
	plt.pie(sizes, labels=labels, #colors=colors,
			autopct='%1.1f%%', shadow=True, startangle=90)
	plt.axis('equal') # Set aspect ratio to be equal so that pie is drawn as a circle.
	plt.title(stitle)
	plt.show()
Esempio n. 29
0
    def pieplot(self, variable):
        """ Plot pie plot for gender or usertype in certain period """
        variable_type = self.data[variable].unique()
        variable_size = []
        if variable == 'gender':
            for i in np.sort(variable_type):
                variable_size.append(round((sum(self.data[variable] == i) / self.data.shape[0] * 100), 2))    # calculate distirbution
            # Gender (Zero=unknown; 1=male; 2=female)
            labels = 'Unknown', 'Male', 'Female'
            sizes = variable_size
            colors = ['lightyellow','lightskyblue', 'lightcoral']
            explode = (0, 0.1, 0.1)  # "explode" the distribution of male and female

            plt.pie(sizes, explode=explode, labels=labels, colors=colors,
                    autopct='%1.1f%%', shadow=True, startangle=90)
            # Set aspect ratio to be equal so that pie is drawn as a circle.
            plt.axis('equal')
            plt.title('Gender Distribution in {}-{}'.format(self.year, self.month), fontsize = 12,y = 1,x=0.12,bbox={'facecolor':'0.8', 'pad':5})
            plt.show()

        elif variable == 'usertype':
            # usertype (Zero=Customer, 1=Subscriber)
            for i in range(2): # change to 0, 1
                variable_size.append(round((sum(self.data[variable] == i) / self.data.shape[0] * 100), 2))    # calculate distribution
            labels = 'Subscriber', 'Customer'
            sizes = variable_size
            colors = ['lightcoral','lightskyblue']
            explode = (0, 0.1)  # only "explode" the subscriber

            plt.pie(sizes, explode=explode, labels=labels, colors=colors,
                    autopct='%1.1f%%', shadow=True, startangle=90)
            # Set aspect ratio to be equal so that pie is drawn as a circle.
            plt.axis('equal')
            plt.title('User Type Distribution in {}-{}'.format(self.year, self.month), fontsize = 12,y = 1,x=0.12,bbox={'facecolor':'0.8', 'pad':5})
            plt.show()
Esempio n. 30
0
def plotTime():
	#Time levels
	pp = PdfPages('time.pdf')
	lev1 = 0
	lev2 = 0
	lev3 = 0
	lev4 = 0
	lev5 = 0
	lev6 = 0
	for time in userTime.keys():
		if len(time) > 0:
			intTime = int(time)
			if intTime < 10:
				lev1 += 1 * userTime[time]
			elif intTime >=10 and intTime < 20:
				lev2 += 1 * userTime[time]
			elif intTime >= 20 and intTime < 30:		
				lev3 += 1 * userTime[time]
			elif intTime >=30 and intTime < 40:		
				lev4 += 1 * userTime[time]
			elif intTime >=40 and intTime < 50:		
				lev5 += 1 * userTime[time]
			else:
				lev6 += 1 * userTime[time]
	labels = '10-', '10-20', '20-30', '30-40', '40-50', '50+'
	sizes = [lev1, lev2, lev3, lev4, lev5, lev6] 		
	colors = ['yellowgreen', 'gold', 'lightskyblue', 'blue', 'lightcoral', 'red']
	plt.figure()
	plt.clf()
	plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True)
	plt.axis('equal')
	pp.savefig()
	pp.close()
def main(with_plots):
    # read data and skip spaces
    data = pd.read_csv('data/weather_data.csv', skipinitialspace=True)
    # transform our data to a dataframe
    df = pd.DataFrame(data)

    # Fill NaN with DEC in Month column
    df['MONTH'].fillna('DEC', inplace=True)

    # filled nans of HIGH and LOW columns
    cubic_interpolate(df, 'HIGH')
    cubic_interpolate(df, 'LOW')

    print('> The median of average temperature is: ' +
          str(df['TEMP'].median()))
    print('> The std of average temperature is: ' + str(df['TEMP'].std()))

    # Find the counts of each direction
    df['DIR'].value_counts()
    direction = df['DIR'].value_counts().index
    counts = df['DIR'].value_counts().values

    # make a pie with the counts percentages of all the days of the year
    plt.title('Percentage of wind direction throughout the year')
    plt.pie(counts, labels=direction, shadow=False, autopct='%1.0f%%')
    plt.axis('equal')

    if with_plots:
        plt.savefig('plots/pie_wind_direction.png')
        plt.show()

    # Group by high Temp and max and get the time of the 4 highest temperatures
    highest_temps = df.groupby('HIGH').max()['TIME'].tail(4)
    print('> The 4 of the highest temperature are: ')
    print(highest_temps)

    print('> Most times the wind was: ' + str(df['DIR'].value_counts()[:1]))
    print('> Max wind speed caused: ' +
          str(df.groupby('WINDHIGH').max()['W_SPEED'].tail(1)))

    # Create a plot with average rain per month
    month_sum_df = df.groupby('MONTH').sum().reset_index()

    month_sum_df.plot(kind='bar', x='MONTH', y='RAIN', legend=None)
    plt.title('Average Rain per month')
    plt.tight_layout()

    if with_plots:
        plt.savefig('plots/avg_rain_monthly.png')
        plt.show()

    # Predict the temperature for 25 December of the next year

    # keep avg temperatures only from December
    y = df['TEMP'][df['MONTH'] == 'DEC']

    # december days from 1 to 31
    x = np.arange(1, len(y) + 0.1, 1)

    I = np.ones((len(x), ))

    A = np.c_[x, I]

    np.linalg.lstsq(A, y, rcond=-1)

    # So for 25 december of the next year
    xp = 25
    yp = -0.18048387 * xp + 14.08129032
    print('> The avg temperature predicted is: ' + str(yp) + ' celcius')

    # Create plots for seasonal temperatures

    # Return temperatures based on season
    def season_temp(col, season):
        return df[col][df['MONTH'].apply(lambda x: x in season)].values

    fig, axs = plt.subplots(2, 2)

    axs[0, 0].plot(season_temp('HIGH', winter_months), 'r-', label='High')
    axs[0, 0].plot(season_temp('TEMP', winter_months), 'g-', label='Average')
    axs[0, 0].plot(season_temp('LOW', winter_months), 'b-', label='Low')
    axs[0, 0].set_title('Winter')

    axs[0, 1].plot(season_temp('HIGH', spring_months), 'r-', label='High')
    axs[0, 1].plot(season_temp('TEMP', spring_months), 'g-', label='Average')
    axs[0, 1].plot(season_temp('LOW', spring_months), 'b-', label='Low')
    axs[0, 1].legend(loc='upper left', bbox_to_anchor=(1, 0.5))
    axs[0, 1].set_title('Spring')

    axs[1, 0].plot(season_temp('HIGH', summer_months), 'r-',
                   season_temp('TEMP', summer_months), 'g-',
                   season_temp('LOW', summer_months), 'b-')
    axs[1, 0].set_title('Summer')

    axs[1, 1].plot(season_temp('HIGH', fall_months), 'r-',
                   season_temp('TEMP', fall_months), 'g-',
                   season_temp('LOW', fall_months), 'b-')
    axs[1, 1].set_title('Fall')

    for ax in axs.flat:
        ax.set(xlabel='Days', ylabel='Temperatures')

    # Hide x labels and tick labels for top plots and y ticks for right plots.
    for ax in axs.flat:
        ax.label_outer()

    plt.suptitle('Seasonal Temperatures')
    if with_plots:
        fig.savefig('plots/temp_per_season.png', bbox_inches='tight')
        plt.show()

    # Get rain status
    print('> Rain status: ')
    rain_status(df['RAIN'].sum())
Esempio n. 32
0
    #给y轴添加标签
    plt.ylabel('Amplitude')

    #添加图形标题
    plt.title('Sin and Cos Waves')

    plt.show()


if __name__ == '__main__':
    #饼图阴影、分裂等属性设置

    # labels参数设置每一块的标签;

    # labeldistance参数设置标签距离圆心的距离(比例值)

    # autopct参数设置比例值小数保留位(%.3f%%);

    # pctdistance参数设置比例值文字距离圆心的距离

    # explode参数设置每一块顶点距圆心的长度(比例值,列表);

    # colors参数设置每一块的颜色(列表);

    # shadow参数为布尔值,设置是否绘制阴影

    # startangle参数设置饼图起始角度
    x = [11, 22, 33, 44]
    plt.pie(x, labels=['a', 'b', 'c', 'd'])

    plt.show()
Esempio n. 33
0
print(
    f"The answer to the 1st question is {data.hospital.value_counts().idxmax()}"
)
data.groupby('hospital').agg({'hospital': 'count'}).plot(kind='bar')
plt.hist(data['hospital'], histtype='bar')
plt.show()

# What is the most common diagnosis among the sports patients?
print(
    f"The answer to the 2nd question is {data[data.hospital=='sports'].diagnosis.value_counts().idxmax()}"
)
# print(f"The answer to the 2nd question is {data.diagnosis.value_counts().max()/1000}")
data.groupby('diagnosis').agg({
    'diagnosis': 'count'
}).plot(kind='pie', y='diagnosis')
plt.pie(data.diagnosis.value_counts())
plt.show()
# print(f"The answer to the 2nd question is {round(data[(data.hospital == 'general') & (data.diagnosis == 'stomach')].shape[0]/data[(data.hospital == 'general')].shape[0], 3)}")

# print(f"The answer to the 3rd question is {round(data[(data.hospital == 'sports') & (data.diagnosis == 'dislocation')].shape[0]/data[(data.hospital == 'sports')].shape[0], 3)}")

# data[(data.hospital == 'general') | (data.hospital == 'sports')].groupby('hospital').agg({'age': 'median'}).diff
# print("The answer to the 4th question is 19.0")

# Build a violin plot of growth distribution by hospitals.
plt.violinplot([
    data[data.hospital == 'general']['height'],
    data[data.hospital == 'prenatal']['height'],
    data[data.hospital == 'sports']['height']
])
plt.show()
Esempio n. 34
0
# Save Figure and print
plt.savefig("C:/Users/May 2018/Pictures/Saved Pictures/Pyberscatterplot.png")
plt.show()


# ## Total Fares by City Type
# In[168]:
# Calculate Total Fares by Type
total_fare_type = merged_data2.groupby(['type']).sum()[["fare"]]

# Build Pie Chart
labels = ["Rural","Suburban","Urban"]
plt.title("% of Total Fares by City Type", fontweight='bold')
colors = ["gold","skyblue","lightcoral"]
explode = (0, 0, 0.1)
plt.pie(total_fare_type, labels=labels, colors=colors, autopct="%1.1f%%", explode=explode, shadow=True, startangle=140)

#Save Figure and display
plt.savefig("C:/Users/May 2018/Pictures/Saved Pictures/Pyberpie1.png")
plt.show()


# ## Total Rides by City Type
# In[170]:
# Calculate Ride Percents
total_ride_type = merged_data2.groupby(['type']).count()[["fare"]]

# Build Pie Chart
labels = ["Rural","Suburban","Urban"]
plt.title("% of Total Rides by City Type", fontweight='bold')
colors = ["gold","skyblue","lightcoral"]
import pandas as pd
from matplotlib import pyplot as plt

fruit = ['Apple', 'Mango', 'Guava', 'Orange', 'PineApple']
quantity = [10, 5, 15, 20, 8]
plt.pie(quantity,
        labels=fruit,
        autopct='%0.1f',
        colors=['yellow', 'blue', 'green', 'red', 'orange'])
plt.show()
plt.pie(quantity,
        labels=fruit,
        radius=2,
        autopct='%0.1f%%',
        colors=['yellow', 'blue', 'green', 'red', 'orange'])
plt.pie([50], radius=1, colors=['w'])
plt.show()
plt.ylabel("Sales")
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5b.pdf')
plt.show()

plt.boxplot(df['Age'])
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5c.pdf')
plt.show()
plt.boxplot(df['Sales'])
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5d.pdf')
plt.show()
plt.boxplot(df['Income'])
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5e.pdf')
plt.show()


plt.pie(df['Age'], labels = {"A", "B", "C","D", "E", "F","G", "H", "I", "J"},
autopct ='% 1.1f %%', shadow = True)
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5f.pdf')
plt.show()
plt.pie(df['Income'], labels = {"A", "B", "C","D", "E", "F","G", "H", "I", "J"},
autopct ='% 1.1f %%', shadow = True)
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5g.pdf')
plt.show()
plt.pie(df['Sales'], labels = {"A", "B", "C","D", "E", "F","G", "H", "I", "J"},
autopct ='% 1.1f %%', shadow = True)
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5h.pdf')
plt.show()

plt.scatter(df['Income'], df['Age'])
plt.savefig('/home/cloudera/Desktop/diwakar/figures/asgn1_5i.pdf')
plt.show()
Esempio n. 37
0
import matplotlib.pyplot as plt

# Data to plot
labels = 'sweet', ' candy ', ' silk ', 'strawberries ', 'marshmallows', 'cheese', 'vanilla', 'tart'
sizes = [13, 12, 5, 3, 3, 3, 2, 1]
colors = [
    'gold', 'yellowgreen', 'lightcoral', 'lightskyblue', 'red', 'purple',
    'magenta', 'blue'
]
explode = (0.1, 0, 0, 0, 0, 0, 0, 0)  # explode 1st slice

# Plot
plt.pie(sizes,
        explode=explode,
        labels=labels,
        colors=colors,
        autopct='%1.1f%%',
        shadow=False,
        startangle=140)

plt.axis('equal')
plt.show()
Esempio n. 38
0
props.append(100 - sum(props))

print "-EVENTS FOUNDS-------------------------------------------------"
print "Number of events found: ", len(eventsindexes)
print "Number of events still to classify: ", totalmovements - len(
    eventsindexes)
print "Total number of movements: ", totalmovements
print "-EVENTS TO GROUP-------------------------------------------------"
for i in (bm.index - eventsindexes)[:10]:
    print bm['Label'][i]

plt.figure()
plt.plot(bm['Amount'][:])
plt.savefig('myAccounting.png')

plt.figure()
#labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
#sizes = [15, 30, 45, 10]
#colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
#explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
groups.append('Misc')
labels = groups
sizes = props
print labels
print sizes

plt.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.savefig('myAccountingByGroups.png')
Esempio n. 39
0
import matplotlib
matplotlib.use("TkAgg")

from matplotlib import pyplot

# 1. Prepare database
labels = ["Web", "iOS", "Android", "React Native"]
values = [40, 20, 35, 15]
colors = ["red", "orange", "yellow", "beige"]
explode = [0, 0.2, 0, 0]

# 2. Plot
pyplot.pie(values, labels=labels, colors=colors, explode=explode, shadow=True)

pyplot.axis("equal")

# 3. Show
pyplot.show()
Esempio n. 40
0
customers = db['customers']

# 4. Create document
# quote = {
#     "title": "Quote",
#     "author": "Đ.T.H.Nhung",
#     "content": """Only I can change my life.
#                   No one can do it for me
#                        -Carol Burnett-"""
# }

# 5. Insert document into collection
# posts.insert_one(quote)
count_ads = customers.count({"ref": "ads"})
count_wom = customers.count({"ref": "wom"})
count_events = customers.count({"ref": "events"})
print(count_ads, count_wom, count_events)

#  use matplotlib to draw a pie chart
# 1. Prepare data
labels = ["Advertisements", "Events", "World of mouth"]
values = [count_ads, count_events, count_wom]
colors = ["green", "red", "yellow"]

# 2. plot
pyplot.pie(values, labels=labels, colors=colors)
pyplot.axis("equal")

# 3. Show
pyplot.show()
Esempio n. 41
0
positive = format(positive, '.2f')
#print(positive)
negative = format(negative, '.2f')
neutral = format(neutral, '.2f')
#print(neutral)

print("How people are reacting on " + searchTerm + " by analyzing " +
      str(noOfSearchTerms) + " Tweets.")

if polarity == 0:
    print("Neutral")
elif polarity > 0.00:
    print("Positive")
elif polarity < 0.00:
    print("Negative")

labels = [
    'Positive [' + str(positive) + '%]', 'Neutral [' + str(neutral) + '%]',
    'Negative [' + str(negative) + '%]'
]
sizes = [positive, neutral, negative]
colors = ['yellowgreen', 'gold', 'red']
patches, text = plt.pie(sizes, colors=colors, startangle=90)
plt.legend(patches, labels, loc="best")
plt.title("How people are reacting on " + searchTerm + " by analyzing " +
          str(noOfSearchTerms) + " Tweets.")
plt.axis('equal')
plt.tight_layout()
plt.show()
Esempio n. 42
0
def home():
    form = SearchForm()

    if form.validate_on_submit():
        flash('Query {}'.format(form.query.data))

        runtime = boto3.client('sagemaker-runtime',
                               aws_access_key_id=aws_access_key_id,
                               aws_secret_access_key=aws_secret_access_key,
                               region_name='us-east-1')

        # get tweets
        if (form.submitUsername.data):
            search_type = 'user'
            search_t = '@'
            tweets = get_users_tweets(form.query.data)
        else:
            search_type = 'hashtag'
            search_t = '#'
            tweets = get_hashtag_tweets(form.query.data)

        #if rate limit was exceeded print message
        if tweets == RATE_ERROR:
            return render_template(
                'index.html',
                form=form,
                error='Rate limit reached. Please wait before trying again')

        #if search error occured print message
        elif tweets == SEARCH_ERROR:
            return render_template(
                'index.html',
                form=form,
                error=
                'An error occured while searching. Please check that your syntax is correct or that the username searched exists and is not private.'
            )

        #if no tweets exist
        elif not tweets:
            return render_template(
                'index.html',
                form=form,
                error='There are no avalible tweets for that user or hashtag')

        else:
            processedTweets = []
            #send each tweet to preprocess function
            for x in tweets['tweet']:
                processedTweets.append(preprocess(x))

            processedTweet = {"tweet": processedTweets}

            #call sentiment alg with processedTweet
            response = runtime.invoke_endpoint(
                EndpointName='twitter-svc-tuner-200324-1449-015-0d842270',
                Body=json.dumps(processedTweet),
                ContentType='application/json')

            results = json.loads(response['Body'].read())

            #aggregates the results into a result object with score, posIndex, and negIndex
            result = aggregateData(results)

            #creates database entry
            now = datetime.now()
            post = {
                "query": form.query.data,
                "type": search_type,
                "score": result['score'],
                "mostPositive": tweets['tweet'][result['posIndex']],
                "mostNegative": tweets['tweet'][result['negIndex']],
                "timeLog": now
            }

            #comment this line out if you dont want to log the results in the database
            collection.insert_one(post)

            #donut chart creation
            # create data
            names = 'Positive', 'Negative',
            size = [result['positive'], result['negative']]

            # Create a circle for the center of the plot
            # change color to = color of background to give illusion of transparency
            my_circle = plt.Circle((0, 0),
                                   0.7,
                                   color='white',
                                   linewidth=1,
                                   ls='-',
                                   ec='white')

            # Give color names and set wedge properites
            plt.pie(size,
                    labels=names,
                    labeldistance=1.1,
                    colors=['skyblue', '#0084b4'],
                    wedgeprops={
                        'linewidth': 4,
                        'edgecolor': 'white'
                    })
            p = plt.gcf()
            p.gca().add_artist(my_circle)

            # needed to send chart as png to html page
            img = BytesIO()
            plt.savefig(img, format='png', transparent=True)
            plt.close()
            img.seek(0)
            donut_url = base64.b64encode(img.getvalue()).decode('utf8')

            new_score = (result['score'] + 1) * 100 / 2
            new_score = round(new_score, 1)

            # Use flash messages to display validation errors and stuff
            return render_template(
                'index.html',
                form=form,
                data=form.query.data,
                search_type=search_t,
                score=new_score,
                posTweet=tweets['tweet'][result['posIndex']],
                negTweet=tweets['tweet'][result['negIndex']],
                donut_url='data:image/png;base64,' + donut_url)

    return render_template('index.html', form=form)
Esempio n. 43
0
    def plot_pruning_pie_chart(self, threshold, to_file="MicroResNet_pie.png"):
        """
		Plots the # of kernels pruned by each kernel pruning criterion

		Pie chart areas:
			- "a": min_eig
			- "b": weight
			- "c": det
			- "d": spectral_radius
			- "e": spectral_norm
			- "f": det_corr
		"""
        pie_chart_vals = {}
        for layer in self.values:
            for neuron in self.values[layer]:
                for kernel in self.values[layer][neuron]:
                    val_dict = self.values[layer][neuron][kernel]
                    n = val_dict["kernel_dim"]

                    # Check decisions of the different criterias
                    min_eig_flag = self.is_pruned(val_dict, threshold,
                                                  "min_eig")
                    weight_flag = self.is_pruned(val_dict, threshold, "weight")
                    det_flag = self.is_pruned(val_dict, pow(threshold, n),
                                              "det")
                    spectral_radius_flag = self.is_pruned(
                        val_dict, threshold, "spectral_radius")
                    spectral_norm_flag = self.is_pruned(
                        val_dict, threshold, "spectral_norm")
                    det_corr_flag = self.is_pruned(val_dict,
                                                   pow(threshold, 2 * n),
                                                   "det_corr")

                    # Process Venn diagram data
                    key = ""
                    if min_eig_flag:
                        key += "a"
                    if weight_flag:
                        key += "b"
                    if det_flag:
                        key += "c"
                    if spectral_radius_flag:
                        key += "d"
                    if spectral_norm_flag:
                        key += "e"
                    if det_corr_flag:
                        key += "f"

                    pie_chart_vals[key] = pie_chart_vals[
                        key] + 1 if key in pie_chart_vals else 1

        # Prepare the chart data
        groups = sorted(list(pie_chart_vals.keys()))
        sizes = [pie_chart_vals[g] for g in groups]
        total = sum(sizes)
        sizes = [(x / float(total)) * 100 for x in sizes]
        groups = ["{%s}" % (",".join(list(g))) for g in groups]
        fig = plt.figure(figsize=(11, 11))

        # Plot the pie chart
        patches, texts, _ = plt.pie(sizes, labels=groups, autopct="%1.1f%%")
        plt.legend(patches, groups, loc="best")
        plt.axis('equal')
        plt.tight_layout()

        # Save the diagram
        plt.savefig(to_file, bbox_inches="tight")
        plt.close(fig)
Esempio n. 44
0
plt.rcParams["font.size"] = 12
plt.rcParams["figure.figsize"] = (12, 8)

# 데이터 계산
value1 = np.array(car_vs_people)
value2 = np.array(car_vs_car)
value3 = np.array(car_only)

# 데이터 범위
ratio = [value1.sum(), value2.sum(), value3.sum()]

# 라벨
labels = ['차 대 사람', '차 대 차', '차량단독']
# 색상
colors = ['#ff6600', '#ff00ff', '#00ffff']
# 확대 비율
explode = [0.0, 0.0, 0.0]

# 파이그래프 표현
plt.pie(ratio, labels=labels, colors=colors, explode=explode,
        autopct='%0.2f%%', shadow=False, startangle=90)

# 그래프 제목
plt.title('2005년 ~ 2017년 유형별 교통 사고 현황')
# 범주 표시
plt.legend()
# 그래프 보이기
plt.show()
# 그래프 종료
plt.close()
Esempio n. 45
0
def main():
    if request.method == 'GET':
        return render_template('index.html')
    query = request.form['query']
    number = request.form['num']
    results = api.search(lang="en",
                         q=query + " -rt",
                         count=number,
                         result_type="recent")

    print("--- Gathered Tweets \n")

    ## open a csv file to store the Tweets and their sentiment
    file_name = 'Sentiment_Analysis_of_{}_Tweets_About_{}.csv'.format(
        number, query)

    with open(file_name, 'w', newline='') as csvfile:
        csv_writer = csv.DictWriter(f=csvfile,
                                    fieldnames=["Tweet", "Sentiment"])
        csv_writer.writeheader()

        print(
            "--- Opened a CSV file to store the results of your sentiment analysis... \n"
        )

        ## tidy up the Tweets and send each to the AYLIEN Text API
        for c, result in enumerate(results, start=1):
            tweet = result.text
            tidy_tweet = tweet.strip().encode('ascii', 'ignore')

            if len(tweet) == 0:
                print('Empty Tweet')
                continue

            response = client.Sentiment({'text': tidy_tweet})
            csv_writer.writerow({
                'Tweet': response['text'],
                'Sentiment': response['polarity']
            })

            print("Analyzed Tweet {}".format(c))

    ## count the data in the Sentiment column of the CSV file
    with open(file_name, 'r') as data:
        counter = Counter()
        for row in csv.DictReader(data):
            counter[row['Sentiment']] += 1

        positive = counter['positive']
        negative = counter['negative']
        neutral = counter['neutral']

    ## declare the variables for the pie chart, using the Counter variables for "sizes"
    colors = ['green', 'red', 'grey']
    sizes = [positive, negative, neutral]
    labels = 'Positive', 'Negative', 'Neutral'

    ## use matplotlib to plot the chart
    plt.pie(x=sizes, shadow=True, colors=colors, labels=labels, startangle=90)

    return render_template('pie_chart.html',
                           title=query,
                           num=number,
                           max=17000,
                           set=zip(sizes, labels, colors))
Esempio n. 46
0
"""
from poster.encode import multipart_encode, MultipartParam
from poster.streaminghttp import register_openers
import urllib2

url="https://api.webempath.net/v2/analyzeWav"
register_openers()
items = []
items.append(MultipartParam('apikey', "o2lvbxnxWBVkLBFrpfb6Tzwp2RRUxsy_bIMzFbsybVo"))
items.append(MultipartParam.from_file('wav', "./sample.wav"))
datagen, headers = multipart_encode(items)
request = urllib2.Request(url, datagen, headers)
response = urllib2.urlopen(request)
if response.getcode() == 200:
    print(response.read())
else:
    print("HTTP status %d" % (response.getcode()))
"""

import numpy as np
import matplotlib.pyplot as plt

x = np.array([100, 200, 300, 400, 500])
plt.pie(x)
plt.show()
Esempio n. 47
0
#Generating the Barchart

objects = ('positive', 'negative', 'neutral')
y_pos = np.arange(len(objects))
performance = [posper, negper, neuper]

plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('percentage of tweets %')
plt.title('sentiment polarities')

plt.show()

#Generating the Pichart

positive = [0]
negative = [0]
neutral = [0]

slices = [posper, negper, neuper]
activities = ['positive', 'negative', 'neutral']
cols = ['c', 'm', 'r', 'k']

plt.pie(slices, labels=activities, colors=cols)

plt.xlabel('x')
plt.ylabel('y')
plt.title('sentiment polarities')
plt.legend()
plt.show()
Esempio n. 48
0
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv("Setor CSV 01.csv")  #Pega o dataset
obj = ("A", "B", "C", "D", "F")  #Rótulos
valores = [
    len(df.loc[df["Grade"] == "A"]),  #Localiza as notas A
    len(df.loc[df["Grade"] == "B"]),  #Localiza as notas B
    len(df.loc[df["Grade"] == "C"]),  #Localiza as notas C
    len(df.loc[df["Grade"] == "D"]),  #Localiza as notas D
    len(df.loc[df["Grade"] == "F"])
]  #Localiza as notas F

colors = ["blue", "red", "grey", "yellow", "orange"]  #Cores
explode = (0.2, 0, 0, 0, 0)  #Valor de afastamento de cada segmento

plt.pie(valores,
        labels=obj,
        explode=explode,
        colors=colors,
        autopct="%1.1f%%",
        shadow=True,
        startangle=12)
#explode é para separar um segmento da tabela
#autopct é para mostrar a porcentagem que o segmento vale na tabela
#shadow define a sombra
#startangle define o angulo inicial
plt.legend(obj)  #Insere as legendas
plt.axis("equal")  #Deixa a tabela redonda
Esempio n. 49
0
import matplotlib.pyplot as plt
import pandas as pd

raw_data = {
    'names': ['Nick', 'Panda', 'S', 'Ari', 'Valos'],
    'jan_ir': [143, 122, 101, 106, 365],
    'feb_ir': [122, 132, 144, 98, 62],
    'march_ir': [65, 88, 12, 32, 65]
}

df = pd.DataFrame(raw_data, columns=['names', 'jan_ir', 'feb_ir', 'march_ir'])

df['total_ir'] = df['jan_ir'] + df['feb_ir'] + df['march_ir']

print(df)

color = [(1, .4, .4), (1, .6, 1), (.5, .3, 1), (.3, 1, .5), (.7, .7, .2)]

plt.pie(df['total_ir'], labels=df['names'], colors=color, autopct='%1.1f%%')
plt.axis('equal')
plt.show()
Esempio n. 50
0
print('数据分析师工资描述:\n{}'.format(df['月工资'].describe()))

# 绘制频率直方图并保存
plt.hist(df['月工资'], bins=12)
plt.xlabel('工资 (千元)')
plt.ylabel('频数')
plt.title("工资直方图")
plt.savefig('histogram.jpg')
plt.show()

# 绘制饼图并保存
count = df['区域'].value_counts()
# 将龙华区和龙华新区的数据汇总
count['龙华新区'] += count['龙华区']
del count['龙华区']
plt.pie(count, labels=count.keys(), labeldistance=1.4, autopct='%2.1f%%')
plt.axis('equal')  # 使饼图为正圆形
plt.legend(loc='upper left', bbox_to_anchor=(-0.1, 1))
plt.savefig('pie_chart.jpg')
plt.show()

# 绘制词云,将职位福利中的字符串汇总
text = ''
for line in df['职位福利']:
    text += line
# 使用jieba模块将字符串分割为单词列表
cut_text = ' '.join(jieba.cut(text))

#color_mask = imread('cloud.jpg')  #设置背景图

wc = WordCloud(background_color="white",
activities = ["sleep", "eat", "play", "sport", "work"]
hours = [7, 2, 5, 3, 8]
#define color in pie chart
'''
Colors can be added to graph by one of the following ways:

    Hex value (#_ _ _ _ _ _)
    rgb value ( r , g , b ) or ( r , g , b , a ) where r, g, b, a are in range 0–1
    grey shades (0–1 range)
    as in active color cycle ( “c0”, “c1”)[capital C followed by digit]
'''
#colors = ['b','r']
colors = ['#ff9999', '#66b3ff', '#99ff99', '#ffcc99', '#00cc99']
#only explode the "work" portion
explode = (0, 0, 0, 0, 0.1)
#autopct = percentage 1 decimal only
plt.pie(hours,
        labels=activities,
        explode=explode,
        shadow=True,
        startangle=90,
        colors=colors,
        autopct='%.1f%%')
plt.title('My Activities')
#draw center circle
centre_circle = plt.Circle((0, 0), 0.70, fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
#show plot
plt.show()
import matplotlib.pyplot as plt

labels = "name1", "name2", "name3", "name4"
#各部分占比
sizes = [20, 30, 40, 10]
#name2突出
explode = (0, 0.1, 0, 0)

plt.pie(sizes,
        explode=explode,
        labels=labels,
        autopct="%1.1f%%",
        shadow=False,
        startangle=90)
#正圆
plt.axis("equal")
plt.show()
Esempio n. 53
0
#Plotting bar graph of 'gender_count'
plt.bar(gender_count.index, gender_count)
plt.show()
#Code starts here

# --------------
#Code starts here
#Storing the value count of 'Alignment'
alignment = data['Alignment'].value_counts()

#Setting the figure size
plt.figure(figsize=(6, 6))

#Plotting pie chart for 'alignment'
plt.pie(alignment,
        labels=alignment.index,
        explode=(0.05, 0.05, 0.05),
        autopct='%1.1f %%')

#Setting the pie chart title
plt.title('Character alignment')

#Code ends here

# --------------
#Code starts here

#Subsetting the data with columns ['Strength', 'Combat']
sc_df = data[['Strength', 'Combat']].copy()

#Finding covariance between 'Strength' and 'Combat'
sc_covariance = sc_df.cov().iloc[0, 1]
Esempio n. 54
0
#%%
#饼图
#sns.set(style='whitegrid')

# data['volume_CATE2'] = data['volume_CATE'].apply(lambda x: x if x<10 else -1)
count = data.groupby(by='volume_CATE').size()
fig = plt.figure(figsize=(6, 6))
plt.pie(x=list(count),
        labels=[
            '0~5', '5~10', '10~15', '15~20', '20~25', '25~30', '30~35',
            '35~40', '40~45', '45~50'
        ],
        explode=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2],
        colors=sns.color_palette('Blues', n_colors=11),
        labeldistance=1.2,
        autopct='%.2f%%',
        pctdistance=0.8,
        radius=2,
        textprops={
            'fontsize': 20,
            'weight': 'bold'
        },
        shadow=True)
plt.savefig('饼图.png', dpi=200, bbox_inches='tight')

#%%
#直方图1
fig = plt.figure(figsize=(10, 6))
sns.distplot(data['aveSpeed'])
plt.tick_params(labelsize=18)
plt.xlabel('平均速度', fontsize=20)
Esempio n. 55
0
import pandas as pd
from apyori import apriori
import matplotlib.pyplot as plt
from apyori import apriori

dataset = pd.read_csv('BreadBasket_DMS.csv')

list1 = dataset.index[dataset['Item'] == 'NONE'].tolist()
dataset.drop(list1, axis=0, inplace=True)

x = dataset['Item'].value_counts()
print("Top 15 selling items are : ")
counts = x[:15].values.tolist()
names = x[:15].index.tolist()

plt.pie(counts, labels=names, autopct="%2.2f%%", radius=3)

item = dataset.groupby('Transaction')['Item'].unique()
item_list = [x.tolist() for x in item]

rules = apriori(item_list, min_support=0.0025, min_confidence=0.2, min_lift=3)

results = list(rules)

for item in results:

    # first index of the inner list
    # Contains base item and add item
    pair = item[0]
    items = [x for x in pair]
    print("Rule: " + items[0] + " -> " + items[1])
Pie chart, where the slices will be ordered and plotted counter-clockwise:
"""

labels = 'CSE', 'ECE', 'IT', 'EE'
sizes = [15, 30, 25, 10]
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue']
explode = (0.5, 0, 0, 0)  # explode 1st slice

#plt.pie(sizes, labels=labels, autopct='%.0f%%')

# or

plt.pie(sizes,
        explode=explode,
        labels=labels,
        colors=colors,
        autopct='%1.2f%%',
        shadow=True,
        startangle=180)

plt.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()
"""
Plotting a bar chart
"""

import matplotlib.pyplot as plt

objects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
performance = [10, 8, 6, 4, 2, 1]
mouse_sex = combined_df.groupby(['Sex']).count()
plot = mouse_sex.plot.pie(y='Mouse ID', figsize=(5, 5))

# In[8]:

# Generate a pie plot showing the distribution of female versus male mice using pyplot
mouse_sex = combined_df.groupby(['Sex']).count()
sizes = mouse_sex['Mouse ID']
labels = ['Male', 'Female']
colors = ["red", "blue"]
explode = (0, 0)

plt.pie(sizes,
        explode=explode,
        labels=labels,
        colors=colors,
        autopct="%1.1f%%",
        shadow=True,
        startangle=140)

# ## Quartiles, outliers and boxplots

# In[45]:

# Calculate the final tumor volume of each mouse across four of the most promising treatment regimens. Calculate the IQR and quantitatively determine if there are any potential outliers.

#find top treatments regimens
top_check = combined_df.groupby(['Drug Regimen']).mean()
top_four = top_check.nsmallest(4, ['Tumor Volume (mm3)'])
top_four
Esempio n. 58
0
score_not_exit = []
for score in range(11):
    if score not in list(table[satisfaction_var]):
        score_not_exit.append(score)

for score in range(11):
    if score in score_not_exit:
        percentage_list.append("%.2f" % round(0, 2))
    else:
        percentage_list.append(
            "%.2f" % round(count_list[score] / total_respond * 100, 2))

labels = '0~4', '5~7', '8~10'
sizes = [
    sum(list(map(float, percentage_list[0:4]))),
    sum(list(map(float, percentage_list[5:7]))),
    sum(list(map(float, percentage_list[8:10])))
]
colors = ['yellowgreen', 'lightskyblue', 'lightcoral']
explode_list = [0, 0, 0.1]
# explode_list[sizes.index(max(sizes))] = 0.1
explode = tuple(explode_list)
'''Plot'''
plt.pie(sizes,
        labels=labels,
        colors=colors,
        autopct='%1.1f%%',
        shadow=True,
        startangle=140)
plt.title('Score Distribution of %s' % app.upper())
data['text'].value_counts()

data.columns

total_sentiment_counts=data['airline_sentiment'].value_counts()
total_sentiment_counts

data.shape

labels = 'negative', 'neutral', 'positive'
colors = ['gold', 'yellowgreen', 'lightcoral']
explode = (0, 0, 0)  # explode 1st slice
 
# Plot
plt.pie(total_sentiment_counts, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)
 
plt.axis('equal')
plt.tight_layout()
plt.show()

#https://www.kaggle.com/rashmitarouy01/us-airlines-twitter-sentiment-analysis

air_senti=pd.crosstab(data.airline, data.airline_sentiment)
air_senti

total_negativereasons_counts=data['negativereason'].value_counts()

data.negativereason.value_counts().plot(kind='pie', autopct='%1.0f%%')

air_nega=pd.crosstab(data.negativereason, data.airline_sentiment)
Esempio n. 60
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 11 16:30:39 2018

@author: taylormade
"""

import matplotlib.pyplot as plt
labels = 'basketball', 'soccer', 'golf', 'baseball'
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0.1, 0, 0, 0)
plt.pie(sizes,
        explode=explode,
        labels=labels,
        colors=colors,
        shadow=False,
        startangle=90)
plt.axis('equal')
plt.show()