반응형
/*********************************************************************************************************
-- Title : [Py2.7] SCATTER, STACKPLOT, PIE Chart w/ Matplotlib.pyplot
-- Reference : pythonprogramming.net
-- Key word : scatter stackplot pie chart 그래프 차트 matplotlib pyplot graph
*********************************************************************************************************/
-- Figure
-- Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # -*- coding: utf-8 -*- import matplotlib.pyplot as plt # ******************************************** # -- SCATTER Chart : 출력 # ******************************************** x = [1,2,3,4,5,6,7,8] y = [5,2,4,2,1,4,5,2] # marker : "matplotlib.org/api/markers_api.html" # s: marker size plt.scatter(x,y, label='skitscat', color='r', s=25, marker="*") plt.xlabel('xlabel') plt.ylabel('ylabel') plt.title('Title: Scatter Chart') plt.legend() plt.show() # ******************************************** # -- STACKPLOT Chart : 출력 # ******************************************** days = [1,2,3,4,5] sleeping = [7,8,6,11,7] eating = [2,3,4,3,2] working = [7,8,7,2,2] playing = [8,5,7,8,13] # -- Label 설정 plt.plot([],[],color='m', label='Sleeping') plt.plot([],[],color='c', label='Eating') plt.plot([],[],color='r', label='Working') plt.plot([],[],color='k', label='Playing') # -- Stackplot 정의 plt.stackplot(days, [sleeping,eating,working,playing], colors=['m','c','r','k']) plt.xlabel('xlabel') plt.ylabel('ylabel') plt.title('Title: Stackplot Chart') plt.legend() plt.show() # ******************************************** # -- PIE Chart : 출력 # ******************************************* slices = [7,2,2,13] activities = ['sleeping','eating','working','playing'] cols = ['c','m','r','b'] plt.pie(slices, labels=activities, colors=cols, startangle=90, shadow= True, explode=(0,0.2,0,0), autopct='%1.1f%%') plt.title('Title: Stackplot Chart') plt.legend() plt.show() | cs |
반응형