Notice
Recent Posts
Recent Comments
관리 메뉴

안까먹을라고 쓰는 블로그

[Python] 모두의 데이터분석 with 파이썬 - 코드(matplot) 본문

Language/Python

[Python] 모두의 데이터분석 with 파이썬 - 코드(matplot)

YawnsDuzin 2019. 10. 21. 18:07

 

반응형

https://matplotlib.org

 

List of named colors — Matplotlib 3.1.1 documentation

Note Click here to download the full example code List of named colors This plots a list of the named colors supported in matplotlib. Note that xkcd colors are supported as well, but are not listed here for brevity. For more information on colors in matplo

matplotlib.org

 

스터디 소스코드

import matplotlib.pyplot as plt
plt.plot([10, 20, 30, 40])
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [12, 43, 25, 15])
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.title('plotting')
plt.plot([10, 20, 30, 40])
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.title('legend')
plt.plot([10, 20, 30, 40], label = 'asc')   # 증가를 의미하는 asc 범례
plt.plot([40, 30, 20, 10], label = 'desc')  # 감소를 의미하는 desc 범례
plt.legend(loc = 8)
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.title('color')
plt.plot([10, 20, 30, 40], color = 'skyblue', label = 'skyblue')
plt.plot([40, 30, 20, 10], 'pink', label='pink')
plt.legend()
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.title('linestyle')
plt.plot([10, 20, 30, 40], color = 'r', linestyle = '--', label = 'dashed')
plt.plot([40, 30, 20, 10], color = 'g', ls = ':', label = 'dotted')
plt.legend()
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.title('marker')
plt.plot([10, 20, 30, 40], 'r.', label = 'circle')
plt.plot([40, 30, 20, 10], 'g^', label = 'triangle up')
plt.legend()
plt.show()

실행 결과

 

import matplotlib.pyplot as plt

plt.hist([1, 1, 2, 3, 4, 5, 6, 6, 7, 8, 10])
plt.show()

실행 결과

 

import random
import matplotlib.pyplot as plt

dice = []

for i in range(1000000):
    dice.append(random.randint(1,6))
# print(dice)

plt.hist(dice, bins = 6)
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
# plt.bar([0, 1, 2, 4, 6, 10], [1, 2, 3, 5, 6, 7])
plt.bar([0, 3, 2, 1, 6, 10], [1, 2, 3, 4, 6, 7])
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.bar(range(6), [1, 2, 3, 5, 6, 7])
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
import random

import numpy as np

result = []

for i in range(13):
    result.append(random.randint(1, 1000))
print(sorted(result))

result2 = np.array(result)
print("1/4 : " + str(np.percentile(result, 25)))
print("2/4 : " + str(np.percentile(result, 50)))
print("3/4 : " + str(np.percentile(result, 75)))

plt.boxplot(result)
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.pie([10, 20])
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
size = [2441, 2312, 1031, 1233]
plt.axis('equal')
plt.pie(size)
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.rc('font', family = 'Malgun Gothic')
size = [2441, 2312, 1031, 1233]
label = ['A형', 'B형', 'AB형', 'O형']
plt.axis('equal')
plt.pie(size, labels = label)
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.rc('font', family = 'Malgun Gothic')
size = [2441, 2312, 1031, 1233]
label = ['A형', 'B형', 'AB형', 'O형']
plt.axis('equal')
plt.pie(size, labels = label, autopct = '%.1f%%')
plt.legend()
plt.show()

실행 결과

 

import matplotlib.pyplot as plt
plt.rc('font', family = 'Malgun Gothic')
size = [2441, 2312, 1031, 1233]
label = ['A형', 'B형', 'AB형', 'O형']
color = ['darkmagenta', 'deeppink', 'hotpink', 'pink']
plt.axis('equal')
plt.pie(size, labels = label, autopct = '%.1f%%', colors = color, explode = (0, 0, 0.2, 0))
plt.legend()
plt.show()

실행 결과

반응형
Comments