Example #1
0
def stem():
    stemgraphic.stem_graphic(df['budget'])
    plt.title('Budget')
    plt.show()
    stemgraphic.stem_graphic(df['gross'])
    plt.title('Gross')
    plt.show()
Example #2
0
#%%
import pandas as pd
import stemgraphic

x = [
    2.9, 0.6, 13.5, 17.1, 2.8, 3.8, 16.0, 2.1, 6.4, 17.2, 7.9, 0.5, 13.7, 11.5,
    2.9, 3.6, 6.1, 8.8, 2.2, 9.4, 15.9, 8.8, 9.8, 11.5, 12.3, 3.7, 8.9, 13.0,
    7.9, 11.7, 6.2, 6.9, 12.8, 13.7, 2.7, 3.5, 8.3, 15.9, 5.1, 6.0
]

y = pd.Series(x)

fig, ax = stemgraphic.stem_graphic(y)

# %%
# frequency histogram

import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

num_bins = 5
n, bins, patches = plt.hist(x, num_bins, facecolor='blue', alpha=0.5)
plt.show()

# %%
import statistics

x1 = [7.625, 7.500, 6.625, 7.625, 6.625, 6.875, 7.375, 5.375, 7.500]

statistics.stdev(x1)
from itertools import groupby
# itertools为迭代器,groupby()会选择出相邻的相同元素例如84,84,84
nums2=[25,45,50,54,55,61,64,68,72,75,75,78,79,81,83,84,84,84,85,86,86,86,87,89,89,89,90,91,91,92,100]
for k,g in groupby(sorted(nums2),key=lambda x: int(x)//10):
    lst=map(str, [int(y)%10 for y in list(g)])
    print(k,'|',' '.join(lst))


import pandas as pd
from stemgraphic import stem_graphic
import matplotlib.pyplot as plt
a=[126,149,143,141,127,123,137,132,135,134,146,142,135,141,150,137,144,137,134,137,148,144,142,137,147,138,140,132,149,131,139,142,138,145,147,137,135,142,151,146,129,120,143,145,142,136,147,128,142,132,138,139,147,128,139,146,139,131,138,149]
# 做出茎叶图
stem_graphic(a)
plt.show()

from itertools import groupby
a=[126,149,143,141,127,123,137,132,135,134,146,142,135,141,150,137,144,137,134,137,148,144,142,137,147,138,140,132,149,131,139,142,138,145,147,137,135,142,151,146,129,120,143,145,142,136,147,128,142,132,138,139,147,128,139,146,139,131,138,149]
for k,g in groupby(sorted(a),key=lambda x: int(x)//10):
    lst=map(str,[int(y)%10 for y in list(g)])
    print(k,'|',' '.join(lst))
freq_table.insert(3, "Cumulative Relative Frequency",
                  (freq_table.frequency / freq_table.frequency.sum() *
                   100).cumsum(), True)
freq_table

# ## Histogram

# In[7]:

selectedData.hist()

# ## Steam Leaf

# In[8]:

fig, ax = stemgraphic.stem_graphic(selectedData)

# ## Central Tendency

# In[9]:

print("Total nilai : ", selectedData.sum())
print("Jumlah data : ", selectedData.count())
print("Mean   : ", selectedData.mean())
print("Median : ", selectedData.median())
print("Mode   : ")
print(selectedData.mode())

# ## Variance

# In[10]:
Example #5
0
def stem_leaf(data):
    fig, ax = stemgraphic.stem_graphic(data, scale=10)
    fig.savefig("stem_leaf.pdf")
mu, sigma = norm.fit(grades)

# Probability Density Function for grades
xmin, xmax = plt.xlim()  #set the xmin and xmax along the x-axis for the pdf
x = np.linspace(xmin - 12, xmax + 10, 100)
p = norm.pdf(x, mu, sigma)

# Plot histogram with PDF
plt.plot(x, p, 'k')
plt.xlabel('Grade')
plt.ylabel('Probability Density')
title = "Historgram of Student Grades\nPDF fit results: mu = %.2f,  sigma = %.2f" % (
    mu, sigma)
plt.title(title)
plt.grid(True)

# Stem-and-Leaf Plot Example 1 SAT scores
fig2, ax2 = stemgraphic.stem_graphic(sat, scale=100, median_alpha=0)
fig2.suptitle("Stem-and-Leaf Plot of SAT Scores")

# Stem-and-Leaf Plot Example 3 Grades
fig3, ax3 = stemgraphic.stem_graphic(grades, scale=10, median_alpha=0)
fig3.suptitle("Stem-and-Leaf Plot of Student Grades")

# Box plot
fig4, ax4 = plt.subplots()
ax4.set_title('Box Plot for Student Grades')
ax4.boxplot(grades, vert=False)

plt.show()
Example #7
0
# 2nd Question:

import matplotlib.pyplot as plt

# pip install stemgraphic

import stemgraphic

points = [
    22, 21, 24, 19, 27, 28, 24, 25, 29, 28, 26, 31, 28, 27, 22, 39, 20, 10, 26,
    24, 27, 28, 26, 28, 18, 32, 29, 25, 31, 27
]

stemgraphic.stem_graphic(points, scale=10)

plt.show()

# outliers are 39 and 10.
    def graficos(self, lista_graf):
        plt.style.use('seaborn-whitegrid')
        plt.switch_backend('SVG')
        plt.cla()
        lista_graf = self.graf_errors(lista_graf)
        tam_graf = len(lista_graf)
        # Pasar imagen a la vista
        figure_graf = io.BytesIO()
        if tam_graf == 1:
            fig = plt.figure(figsize=(10, 8))
        if tam_graf > 1:
            fig = plt.figure(figsize=(10, 14))
        if tam_graf > 2:
            fig = plt.figure(figsize=(10, 20))
        if tam_graf > 3:
            fig = plt.figure(figsize=(10, 28))
        cont = 1

        if 'pie' in lista_graf:
            lista_explode = [0.2] * len(self.indices)
            ax_sec = fig.add_subplot(tam_graf, 1, cont)
            ax_sec.pie(self.frec_ab,
                       explode=lista_explode,
                       labels=self.indices,
                       autopct='%1.1f%%',
                       startangle=180)
            ax_sec.axis('equal')
            ax_sec.set_title(f'Diagrama de sectores: {self.var}')
            cont += 1

        if 'bar' in lista_graf:
            colors_graf = 'grbmcyk'
            lista_colores = []
            j = 0
            for i in range(len(self.indices)):
                if j >= len(colors_graf):
                    j = 0
                lista_colores.append(colors_graf[j])
                j += 1

            ax_bar = fig.add_subplot(tam_graf, 1, cont)
            ax_bar.bar(self.indices,
                       self.frec_ab,
                       width=0.8,
                       color=lista_colores)
            ax_bar.set_ylabel('Número de Alumnos')
            ax_bar.set_title(f'Diagrama de Barras: {self.var}')
            ax_bar.set_xticklabels(self.indices,
                                   rotation=45,
                                   horizontalalignment='right')
            for index, value in zip(self.indices, self.frec_ab):
                ax_bar.text(index,
                            value,
                            str(value),
                            color='black',
                            ha='center')
            cont += 1

        if 'poli' in lista_graf:
            ax_poli = fig.add_subplot(tam_graf, 1, cont)
            ax_poli.plot(np.arange(len(self.indices)), self.frec_ab)
            ax_poli.set_ylabel('Número de Alumnos')
            ax_poli.set_title(f'Polígono de Frecuencias: {self.var}')
            ax_poli.set_xticks(np.arange(len(self.indices)))
            ax_poli.set_xticklabels(self.indices,
                                    rotation=45,
                                    horizontalalignment='right')
            cont += 1

        if 'histo' in lista_graf:
            ax_hist = fig.add_subplot(tam_graf, 1, cont)
            plt.hist(self.valores, bins=25, facecolor='g', alpha=0.8)
            ax_hist.set_ylabel('Número de Alumnos')
            ax_hist.set_title(f'Histograma: {self.var}')
            cont += 1

        if 'caja' in lista_graf:
            ax_box = fig.add_subplot(tam_graf, 1, cont)
            ax_box.set_title(f'Diagrama de caja y patilla: {self.var}')
            ax_box.set_ylabel(self.var)
            ax_box.boxplot(self.valores)
            cont += 1

        if 'tallo' in lista_graf:
            ax_tallo = fig.add_subplot(tam_graf, 1, cont)
            ax_tallo.set_title(f'Diagrama de tallo y hoja: {self.var}')
            ax_tallo.set_ylabel(self.var)
            if self.var == 'Aciertos' or self.var == 'Fallos' or self.var == 'Total_prueba':
                stemgraphic.stem_graphic(self.valores, scale=10, ax=ax_tallo)
            else:
                stemgraphic.stem_graphic(self.valores, ax=ax_tallo)
            cont += 1

        plt.tight_layout(h_pad=5.0)
        plt.savefig(figure_graf, format="png")
        graf_final = base64.b64encode(
            figure_graf.getvalue()).decode('utf-8').replace('\n', '')
        return (graf_final)
Example #9
0
hist[1].set_title('Amount of Projects Corresponding to Pledged Money',
                  fontsize=10)
hist[1].set_ylabel("Quatity")
hist[1].set_xlabel("Pledged (Million USD)")
hist[1].hist(y)

#Stem

#set X axis
#Goal
# goal_axis = []
# for ele in x :
#     goal_axis.append(int(str(ele)[:1]))

# stem[0].set_title('Stem and leaf : Goal',fontsize=12)
# stem[0].set_xlabel('STEM',fontsize=8)
# stem[0].set_ylabel('Goal (Million USD)',fontsize=12)
# stem[0].stem(goal_axis,x)
stem[0] = stg.stem_graphic(x)

# #Pledged
# pledged_axis =[]
# for ele in y:
#     pledged_axis.append(int(str(ele)[:1]))
# stem[1].set_title('Stem and leaf : Pledged',fontsize=12)
# stem[1].set_xlabel('STEM',fontsize=8)
# stem[1].set_ylabel('Pledged (Million USD)',fontsize=12)
# stem[1].stem(pledged_axis,y)
stem[1] = stg.stem_graphic(y)

plt.show()
Example #10
0
def stemplot(data):
    stemgraphic.stem_graphic(data, scale=1)
Example #11
0
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 17:10:02 2020

@author: kimyongkuk
"""

from pandas import DataFrame
from pandas import read_csv
from matplotlib import pyplot
from stemgraphic import stem_graphic

grade_csv = read_csv("data/grade.csv", encoding='euc-kr')

#전처리 컬럼 이름을 인덱스로 설정
grade_df = grade_csv.rename(index=grade_csv['이름']).drop('이름', axis=1)

#평균점수 컬럼 추가: axis=1 행
grade_df['평균'] = grade_df.mean(axis=1)
print(grade_df)

pyplot.rcParams['font.family'] = 'Malgun Gothic'
pyplot.rcParams['font.size'] = 20
pyplot.rcParams['figure.figsize'] = (15, 8)

stem_graphic(grade_df['평균'], scale=10)
pyplot.savefig('stem.png')