import pandas as pd
import matplotlib.pyplot as plt

class PIE:

    def __init__(self):

        self._xlsx = PIE.getConfig()
        self._category = {"남자" : 0, "여자" : 0}

    def doPie(self):

        for i in self._xlsx.index:
            rowData = self._xlsx["성별"][i], self._xlsx["방문자수"][i]
            self._category[rowData[0]] += rowData[1]

        category         = ["man", "woman"]
        categorySize     = [self._category["남자"], self._category["여자"]]
        categoryColors   = ["yellow", "green"]
        categoryExplodes = (0.1, 0)

        plt.pie(categorySize,
                explode      = categoryExplodes,
                labels       = category,
                colors       = categoryColors,
                autopct      = '%1.2f%%',
                shadow       = True,
                startangle   = 90,
                textprops    = {"fontsize" : 14})  # text font size
        plt.axis("equal")
        plt.show()

    @classmethod
    def getConfig(cls):

        PATH      = "/home/kim/Desktop/PY.dir/stu_01.dir/KimJH.xlsx"
        SHEETNAME = "demographicsDashboard"
        xlxsObj = pd.read_excel(PATH, sheet_name=SHEETNAME)

        return xlxsObj

def main():

    obj = PIE()
    obj.doPie()

if __name__ == "__main__":
    main()

 

 

 

'python > matplolib' 카테고리의 다른 글

matplotlib => line_chart + excel  (0) 2019.11.02