Matplotlib 그래프 그리기 기초 titanic 데이터 불러오기
|
import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset('titanic') df10 = df.iloc[:10] |
그래프 1
|
plt.figure(figsize=(4,3)) plt.plot(df10['fare']) plt.show() |
그래프 2
|
plt.figure(figsize=(4,3)) plt.plot(df10['fare']) plt.plot(df10['age']) plt.show() |
그래프 3
|
plt.figure(figsize=(8,3)) plt.subplot(1,2,1) plt.plot(df10['fare']) plt.subplot(1,2,2) plt.plot(df10['age']) plt.show() |
그래프 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
plt.figure(figsize=(8,3)) plt.subplot(1,2,1) plt.plot(df10['fare']) plt.title('titanic fare') plt.xlabel('index') plt.ylabel('fare') plt.ylim(0, 100) plt.legend(labels=['fare'], loc='best') plt.subplot(1,2,2) plt.plot(df10['age']) plt.title('titanic age') plt.xlabel('index') plt.ylabel('age') plt.ylim(0, 100) plt.legend(labels=['age'], loc='best') plt.show() |
그래프 5
|
plt.figure(figsize=(3,2)) plt.plot([1,3,2,4]) plt.show() |
그래프 6
|
import matplotlib.pyplot as plt x = [1,2,3,4] y = [2,4,6,8] plt.figure(figsize=(3,2)) plt.plot(x, y) plt.show() |
그래프 7
|
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-10,10,100) y = x * 2 y2 = 2 * x * x y3 = np.sin(x) * 100 plt.figure(figsize=(3,2)) plt.plot(x, y) plt.plot(x, y2) plt.plot(x, y3) plt.show() |
그래프 8
|
import matplotlib.pyplot as plt plt.figure(figsize=(3,2), facecolor='g', edgecolor='r') plt.plot([1,2,3,4], [1,4,9,16], 'gx-') plt.show() |
그래프 9
|
import matplotlib.pyplot as plt name = ['James', 'Jane', 'Tom', 'Adam'] kor = [100, 50, 100, 90] eng = [90, 86, 94, 79] xpos = np.arange(len(kor)) plt.figure(figsize=(3,2)) plt.bar(xpos, kor, width=0.3) plt.bar(xpos+0.32, eng, width=0.3) plt.xticks(xpos, name) plt.show() |
그래프 10
|
import matplotlib.pyplot as plt name = ['James', 'Jane', 'Tom', 'Adam'] kor = [100, 50, 100, 90] eng = [90, 86, 94, 79] ypos = np.arange(len(kor)) plt.figure(figsize=(3,2)) plt.barh(ypos, kor, height=0.3) plt.barh(ypos+0.32, eng, height=0.3) plt.yticks(xpos, name) plt.title('Sungjuk') plt.show() |
그래프 11
|
import matplotlib.pyplot as plt name = ['James', 'Jane', 'Tom', 'Adam'] kor = [100, 50, 100, 90] eng = [90, 86, 94, 79] plt.figure(figsize=(3,2)) plt.pie(kor, labels=name) plt.title('Sungjuk') plt.show() |
그래프 12
|
import matplotlib.pyplot as plt import numpy as np import math #X = range(100) #Y = [math.sin(v) for v in X] #X = np.arange(100) #Y = np.sin(X) X = np.linspace(0,100,101) Y = np.sin(X) plt.figure(figsize=(3,2)) plt.plot(X, Y) plt.show() |
그래프 13
|
import matplotlib.pyplot as plt name = ['James', 'Jane', 'Tom', 'Adam'] kor = [100, 50, 100, 90] eng = [90, 86, 94, 79] plt.figure(figsize=(2,2)) plt.scatter(kor, eng) plt.title('Sungjuk') plt.show() |
그래프 14
|
import seaborn as sns import matplotlib.pyplot as plt df = sns.load_dataset('titanic') plt.figure(figsize=(3,3)) plt.scatter(df['age'], df['fare'], marker='o', s=15, alpha=0.1) plt.show() |
… Continue Reading Part 4. 시각화 도구