본문 바로가기
python

Seaborn 시각화 연습_Heatmap,Pairplot,jointplot,tsplot

by aesup 2021. 5. 14.
728x90

Pinkwink님 블로그를 보고 연습하였다.

https://pinkwink.kr/986?category=522424

pairplot 이랑 jointplot은 정말 유용하게 사용 할 수 있을거 같다.

 

[Seaborn 연재] pairplot, jointplot, tsplot 익히기

Seaborn이 제공하는 그래프 중에 오늘은 pairplot, jointplot, tsplot에 대해 이야기를 할려고 합니다^^. 특히 pairplot이 주는 재미난 결과는 꽤 마음에 드실겁니다.^^ Seaborn [Seaborn 연재] set_style과 boxpl..

pinkwink.kr

 

 

In [12]:

import numpy as np import seaborn as sns from matplotlib import pyplot as plt

In [17]:

x = np.random.rand( 5, 12) x

Out[17]:

array([[0.03324251, 0.88104451, 0.27053807, 0.8320188 , 0.49092681, 0.75255923, 0.15278282, 0.73902481, 0.86908686, 0.45668774, 0.31050087, 0.15716642], [0.67982771, 0.59736936, 0.45207916, 0.59698116, 0.55910991, 0.3271498 , 0.77314427, 0.30645617, 0.80380316, 0.79532911, 0.42675504, 0.17486688], [0.86124541, 0.21337203, 0.16131834, 0.05187921, 0.19474029, 0.30777195, 0.36514702, 0.29470368, 0.5188736 , 0.85080587, 0.46255703, 0.04595159], [0.31246925, 0.38037254, 0.04014281, 0.8491799 , 0.72682537, 0.01165201, 0.9666183 , 0.65619396, 0.39759107, 0.16876977, 0.96138433, 0.83583517], [0.66950724, 0.12716263, 0.41842518, 0.09924881, 0.48370869, 0.76010372, 0.60450044, 0.13803113, 0.00321277, 0.38555838, 0.51358915, 0.50555199]])

 

Heatmap

In [18]:

sns.heatmap(x, vmin=0, vmax=1)

Out[18]:

<matplotlib.axes._subplots.AxesSubplot at 0x1a37f9078c8>

 

In [15]:

flights= sns.load_dataset("flights") flights.head()

Out[15]:

 yearmonthpassengers

0 1949 January 112
1 1949 February 118
2 1949 March 132
3 1949 April 129
4 1949 May 121

In [16]:

flights = flights.pivot( "month", "year", "passengers" ) flights.head(5)

Out[16]:

year194919501951195219531954195519561957195819591960month            

January 112 115 145 171 196 204 242 284 315 340 360 417
February 118 126 150 180 196 188 233 277 301 318 342 391
March 132 141 178 193 236 235 267 317 356 362 406 419
April 129 135 163 181 235 227 269 313 348 348 396 461
May 121 125 172 183 229 234 270 318 355 363 420 472

In [11]:

plt.figure(figsize = (10, 8)) sns.heatmap(flights, annot = True, fmt = "d") plt.show()

 

 

Pairplot

In [19]:

sns.set(style = "ticks",color_codes=True) iris = sns.load_dataset("iris") iris.head(5)

Out[19]:

 sepal_lengthsepal_widthpetal_lengthpetal_widthspecies

0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

In [27]:

sns.pairplot(iris, hue = "species", palette ="husl" )

Out[27]:

<seaborn.axisgrid.PairGrid at 0x1a305042788>

 

 

Jointplot

In [28]:

tips = sns.load_dataset("tips") tips.head(5)

Out[28]:

 total_billtipsexsmokerdaytimesize

0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

In [30]:

sns.set_style("whitegrid") sns.jointplot(x="total_bill", y = "tip", data = tips) plt.show() #jointplot은 scatter 플롯을 보이면서도 또 각 축에 히스토그램을 보여준다.

 

In [32]:

iris = sns.load_dataset("iris") sns.jointplot("sepal_width", "petal_length", data = iris, kind ="kde", color ="r")

Out[32]:

<seaborn.axisgrid.JointGrid at 0x1a307134908>

 

 

Tsplot

In [37]:

x = np.linspace( 0 , 15, 31) data = np.sin(x) + np.random.rand(10,31) + np.random.randn(10, 1) data sns.tsplot(data = data, err_style= "boot_traces", n_boot = 200)

 

C:\Users\swcheon\Anaconda3\lib\site-packages\seaborn\timeseries.py:183: UserWarning: The `tsplot` function is deprecated and will be removed in a future release. Please update your code to use the new `lineplot` function. warnings.warn(msg, UserWarning)

Out[37]:

<matplotlib.axes._subplots.AxesSubplot at 0x1a307395388>

 

In [ ]:

 

728x90