import seaborn as snssns.load_dataset('anscombe'): seaborn에서 제공하는 이미 만들어진 데이터셋 예제 들고오기. 데이터프레임으로 들고온다.hist, ax1 = plt.subplots()
sns.histplot(data=tips, x='total_bill', ax=ax1)
plt.show()

den, ax1 = plt.subplots()
sns.kdeplot(data=tips, x='total_bill', ax=ax1)
plt.show()

fig, ax1 = plt.subplots()
sns.rugplot(data=tips, x='total_bill', ax=ax1)
sns.histplot(data=tips, x='total_bill', ax=ax1)
plt.show()

fig = sns.displot(data=tips, x='total_bill', kde=True, rug=True)
fig.set_axis_labels(x_var='Total Bill', y_var='Count')
plt.show()

count, ax1 = plt.subplots()
sns.countplot(data=tips, x='day', palette='viridis', ax=ax1)
plt.show()


crime_anal_norm_sort = crime_anal_norm.sort_values(by='검거', ascending=False)
plt.figure(figsize = (10,10))
sns.heatmap(crime_anal_norm_sort[target_col], annot=True, fmt='f',
linewidths=.5, cmap='Spectral') #색만 조금 다르게 설정
plt.title('범죄 검거 비율 (정규화된 검거의 합으로 정렬)')
plt.show()
sns.heatmap(): 히트맵 형태로 시각화. 데이터의 값에 따라 색상의 강도를 다르게 해서 데이터 패턴이나 변화를 보여줌.annot=True: 각 셀에 데이터값 표시.fmt=f: annot의 데이터값을 어떻게 표기할지. f는 고정 소수점 형식.linewidths=.5: 셀간 경계선 너비.cmap=: 히트맵에 사용할 컬러맵.
scatter, ax1 = plt.subplots()
sns.scatterplot(data=tips, x='total_bill', y='tip', ax=ax1)
plt.show()

(2) 방법 2: regression(회귀선)이 같이 찍힘. 이게 더 포괄적인 그래프 그리기 함수. ax1의 데이터타입: axes.
fig, ax1 = plt.subplots()
sns.regplot(data=tips, x='total_bill', y='tip', ax=ax1)
plt.show()

(3) 방법3: 이것도 회귀선 같이 찍힌다. 이 경우 col='sex'로 하면, 성별로 따로 그래프 찍힌다. hue='smoker'로 하면 흡연자 색깔로 구분해서 찍는다. 없으면 그냥 전체로. fig의 데이터타입: FacetGrid.
fig = sns.lmplot(data=tips, x='total_bill', y='tip', col='sex', hue='smoker')
plt.show()


joint = sns.jointplot(data=tips, x='total_bill', y='tip')
joint.set_axis_labels(xlabel='Total Bill', ylabel='Tip')
joint.figure.suptitle('Joint Plot of Total Bill and Tip', y=1.03) # y는 타이틀 위치 y축
plt.show()

hexbin = sns.jointplot(data=tips, x='total_bill', y='tip', kind='hex')
hexbin.set_axis_labels(xlabel='Total Bill', ylabel='Tip')
hexbin.figure.suptitle('Hexbin Plot of Total Bill and Tip', y=1.03)
plt.show()

kde, ax1 = plt.subplots()
sns.kdeplot(data=tips, x='total_bill', y='tip', fill=True, ax=ax1)
plt.show()

kde2d = sns.jointplot(data=tips, x='total_bill', y='tip', kind='kde')
kde2d.set_axis_labels(xlabel='Total Bill', ylabel='Tip')
kde2d.figure.suptitle('KDE Plot of Total Bill and Tip', y=1.03)
plt.show()

fig, ax1 = plt.subplots()
sns.barplot(data=tips, x='time', y='total_bill', estimator=np.mean, ci=95, ax=ax1)
plt.show()

order=['young', 'middle', 'old'] 이렇게 매개변수로 값의 순서를 지정할 수도 있다. fig, ax1 = plt.subplots()
sns.boxplot(data=tips, x='time', y='total_bill', ax=ax1)
plt.show()


hue, col(?)
fig, ax1 = plt.subplots()
sns.violinplot(data=tips, x='time', y='total_bill', ax=ax1)
plt.show()

box_violin, (ax1, ax2) = plt.subplots(nrows=1, ncols=2)
sns.boxplot(data=tips, x='time', y='total_bill', ax=ax1)
sns.violinplot(data=tips, x='time', y='total_bill', ax=ax2)
ax1.set_title('Box Plot')
ax1.set_xlabel('Time of Day')
ax1.set_ylabel('Total Bill')
ax2.set_title('Violoin plot')
ax2.set_xlabel('Time of Day')
ax2.set_ylabel('Total Bill')
box_violin.suptitle('Comparison of Box Plot with Violin Plot')
box_violin.set_tight_layout(True)
plt.show()
pair_grid = sns.PairGrid(tips, diag_sharey=False)
pair_grid = pair_grid.map_upper(sns.regplot)
pair_grid = pair_grid.map_lower(sns.kdeplot)
pair_grid = pair_grid.map_diag(sns.histplot)
plt.show()

diag는 대각선 부분인데, 이 부분은 같은 변수끼리의 조합이다. 따라서 단변수 그래프인 히스토그램을 그린다. upper은 상삼각 부분이고, 여기는 산포도, 회귀선 그래프를 그린다lower은 하삼각 부분이고, 여기는 kde 그래프를 그린다. diag_sharey=False 이건, 각각의 서브플롯 y축이 자체적인 범위를 가지도록 설정하는 것. 이걸 True로 하면 9개의 서브플롯 y축의 범위가 모두 같아진다. fig = sns.pairplot(data=tips)
fig.figure.suptitle('Pairwise Relationships of the Tips Data', y=1.03)
plt.show()

kind=로 지정할 수 있다. reg(산점도, 선형회귀선 함께), scatter(산점도), kde(커널 밀도 추정), hist(히스토그램)fig, ax1 = plt.subplots()
sns.violinplot(data=tips,
x='time',
y='total_bill',
hue='smoker',
split=True,
palette='viridis',
ax=ax1)
plt.show()

fig = sns.pairplot(tips, hue='time', palette='viridis')
plt.show()
barplot().set(): seaborn, matplotlib에서 그래프의 여러 속성을 한 번에 설정하는 메서드. colors = sns.color_palette('Paired',len(data_result.index)): sns에 있는 컬러 팔레트를 생성하는 함수. Paired는 색상 이름, len()부분은 생성할 색깔 갯수. 여기서는 index개수만큼 생성한다는 뜻. 왜냐하면 plt에서 c 매개변수로 색상을 지정할 때, 색상의 리스트가 들어가면, 그건 데이터포인트수와 갯수가 동일해야 하기 때문.