🤝

Visualizing statistical relationships

서문

Statistical analysis is a process of understanding how variables in a dataset relate to each other and how those relationships depend on other variables. Visualization can be a core component of this process because, when data are visualized properly, the human visual system can see trends and patterns that indicate a relationship.
통계 분석은 데이터 세트 속 변수들이 각각 어떻게 연관되어 있는지, 그리고 그 관계가 또 다른 변수와는 어떻게 걸쳐있는지 (depend on) 이해하는 과정이다. 시각화는 이러한 과정의 핵심 요소라고 볼 수 있다. 왜냐하면 데이터가 적합하게 시각화 될 때 비로소, 우리의 눈이 관계를 나타내는 트렌드와 패턴을 파악할 수 있기 때문이다.
We will discuss three seaborn functions in this tutorial. The one we will use most is relplot(). This is a figure-level function for visualizing statistical relationships using two common approaches: scatter plots and line plots. relplot() combines a FacetGrid with one of two axes-level functions:
이번 튜토리얼에서는 3가지 Seaborn의 클래스에 대해서 알아 볼 것이다.
그 중 가장 자주 쓸 것이 바로 relplot() 이다. 이 "relation plot"은 기본적으로 통계적 관계들을 시각화하는 Figure-level에 속하는 클래스이다. 이때 relplot()은 두 가지 공통적인 접근방식을 사용하고 있다.
하나는 산점도 (scatter plots)이고, 또 하나는 선 그래프 (line plots) 이다.
나아가 relplot()FacetGrid(파셋 그리드)라는 Seaborn의 클래스와 함께 쓰인다. 파셋 그리드는 axes-level에 속하는 두 개의 클래스 중 하나이다.
Figure와 Axes 개념 구분을 위한 참고 이미지
scatterplot() (with kind="scatter"; the default)
lineplot() (with kind="line")
As we will see, these functions can be quite illuminating because they use simple and easily-understood representations of data that can nevertheless represent complex dataset structures. They can do so because they plot two-dimensional graphics that can be enhanced by mapping up to three additional variables using the semantics of hue, size, and style.
각 plot의 링크에 들어가 예시를 통해 확인할 수 있듯, 이 두 도표들 모두 데이터들을 상당히 잘 표현하고 있다. 비록 데이터 세트의 구조는 복잡했지만, 이를 표현함에 있어서 간단하면서도 쉽게 이해되는 방식으로 나타냈기 때문이다. 이는 2차원 도표를 쓰면서도 hue, size, style이라는 추가적인 변수들을 사용해 표현력이 한층 끌어 올렸기 때문에 가능한 일이다.
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set(style="darkgrid")
Python

Relating variables with scatter plots¶

산점도를 통해 변수들을 연결하기
The scatter plot is a mainstay of statistical visualization. It depicts the joint distribution of two variables using a cloud of points, where each point represents an observation in the dataset. This depiction allows the eye to infer a substantial amount of information about whether there is any meaningful relationship between them.
산점도야 말로 통계적 시각화의 중추라고 할 수 있다. 산점도는 데이터를 기반으로 형성된 점들의 뭉치(cloud)를 사용해 두 변수 간의 공통적인 분포를 묘사하는 그래프이다. 이를 보는 사람은 변수 간의 실질적인 정보, 즉 의미있는 상관관계 등을 추론할 수 있다.
There are several ways to draw a scatter plot in seaborn. The most basic, which should be used when both variables are numeric, is the scatterplot() function. In the categorical visualization tutorial, we will see specialized tools for using scatterplots to visualize categorical data. The scatterplot() is the default kind in relplot() (it can also be forced by setting kind="scatter"):
Seaborn 패키지를 통해 산점도를 그리는 방법이 하나만 있는 건 아니다. 가장 기본이 되는 것은 x, y 두 축을 이루는 변수가 모두 숫자로 표현될 수 있는 양적 데이터 기반의 scatterplot() 클래스이다. 이와 다르게 명목 범주들을 시각화 해보는 튜토리얼에서는 좀 더 특별한 툴을 써볼 것이다. scatterplot()relplot()의 디폴트 방식 (kind) 으로 지정되어 있다.
(물론 kind = "scatter" 를 통해 직접 명령할 수도 있다)
tips = sns.load_dataset("tips") sns.relplot(x="total_bill", y="tip", data=tips);
Python
While the points are plotted in two dimensions, another dimension can be added to the plot by coloring the points according to a third variable. In seaborn, this is referred to as using a “hue semantic”, because the color of the point gains meaning:
점들이 2차원 화면에 기입되는 동안, 또 다른 차원의 개념을 추가할 수 있다. 세 번째 변수는 점들의 색깔을 달리하여 표현하는 것이다. Seaborn에서는 이를 "hue semantic" 즉 "색 구분을 통한 의미 전달" 용법을 사용했다고 표현한다. 점들이 각자의 의미들을 가졌기 때문이다.
( 역주 :이후 hue semantic에 대한 번역은 "hue를 통한 의미구분" 이라고 표현하였습니다)
sns.relplot(x="total_bill", y="tip", hue="smoker", data=tips);
Python
To emphasize the difference between the classes, and to improve accessibility, you can use a different marker style for each class:
클래스 간의 차이를 더 강조하고 싶거나, 좀 더 효과적으로 표현하기 위해서는 점의 스타일을 달리할 수 있다 :
sns.relplot(x="total_bill", y="tip", hue="smoker", style="smoker", data=tips);
Python
It’s also possible to represent four variables by changing the hue and style of each point independently. But this should be done carefully, because the eye is much less sensitive to shape than to color:
4개의 변수까지도 색과 스타일을 달리하여 표현하는 게 가능하다. 하지만 눈으로 스타일 차이 (점 모양의 차이)를 인식하는 게 색깔 차이를 구분하는 것보다 어렵기 때문에 이때는 주의해야 한다.
sns.relplot(x="total_bill", y="tip", hue="smoker", style="time", data=tips);
Python
In the examples above, the hue semantic was categorical, so the default qualitative palette was applied. If the hue semantic is numeric (specifically, if it can be cast to float), the default coloring switches to a sequential palette:
위 예시를 보면, 명목범주의 구분을 hue를 통해 구분하였기 때문에 기본 색깔 팔레트가 적용되었다. 만약 hue로 구분한 값이 수치화된 데이터였다면 (특별히, 만약 그 수치화된 구분이 정수 단위가 아닌 실수float 단위였다면) 점의 색은 채도가 데이터 크기에 따라 *점진적으로 색이 변해가는 팔레트를 기본적으로 사용하게 된다.
*해당 팔레트는 데이터에 따라 색이 조금씩 변해가기 때문에 "시퀀셜sequential 팔레트"라고 부르며 튜토리얼 후반부에서 다시 다룬다.
sns.relplot(x="total_bill", y="tip", hue="size", data=tips);
Python
In both cases, you can customize the color palette. There are many options for doing so. Here, we customize a sequential palette using the string interface to cubehelix_palette():
물론 그 두 경우 모두 컬러 팔레트를 커스터마이징 할 수 있고 그를 위한 옵션들도 많이 준비되어 있다. 여기선, 스트링 타입으로 cubehelix_palette() 를 조작하는 인터페이스를 사용해 봄으로써 시퀀셜 팔레트를 커스터마이징 해볼 것이다.
cubehelix란 정사각형모양이란 뜻으로, cubehelix는 위와 같이 색이 변해가는 팔레트를 말한다. (완전히 스무스하게 색이 변하가는 팔레트는 아니고, 단계적으로descrete 색이 변해감)
sns.relplot(x="total_bill", y="tip", hue="size", palette="ch:r=-.5,l=.75", data=tips);
Python
The third kind of semantic variable changes the size of each point:
세번째로 소개할 의미를 담는 변수는 각 점들의 크기 변화이다.
sns.relplot(x="total_bill", y="tip", size="size", data=tips);
Python
Unlike with matplotlib.pyplot.scatter(), the literal value of the variable is not used to pick the area of the point. Instead, the range of values in data units is normalized into a range in area units. This range can be customized:
matplotlib.pyplot.scatter() 와는 다르게, sizes 인자(arguments)에 기입한 값sizes = (15, 200)이 점의 영역을 표현하는데 바로 반영되진 않는다. 대신, 원래 데이터가 갖고 있는 범위와 매개변수로 입력해 둔 범위를 정규화를 통해 맞춘다. 아래 코드에서 설정한 범위sizes = (15, 200)는 다음과 같이 커스터마이징 될 수 있다.
sns.relplot(x="total_bill", y="tip", size="size", sizes=(15, 200), data=tips);
Python
More examples for customizing how the different semantics are used to show statistical relationships are shown in the scatterplot() API examples.
통계적 관계를 나타내기 위해 각기 다른 의미를 가진 변수를 사용하는 기법에 대한 더 많은 예시는 scatterplot() 의 API 예시들에서 볼 수 있다.

Emphasizing continuity with line plots¶

선 그래프를 통해 지속되고 있음을 강조하는 기법
Scatter plots are highly effective, but there is no universally optimal type of visualisation. Instead, the visual representation should be adapted for the specifics of the dataset and to the question you are trying to answer with the plot.
산점도는 매우 효과적이지만, 글로벌하게 통용되는 최적의 표현 방식이 정해져 있는 건 아니다. 대신 데이터 셋의 종류나 해결하고자 하는 물음에 잘 대응하여 시각화를 진행해야한다.
With some datasets, you may want to understand changes in one variable as a function of time, or a similarly continuous variable. In this situation, a good choice is to draw a line plot. In seaborn, this can be accomplished by the lineplot() function, either directly or with relplot() by setting kind="line":
데이터 셋을 표현함에 있어써, 시간이 지나는 것 혹은 그와 유사한 지속성을 갖고 있는 변수를 이해하고 싶을 때도 있다. 이러한 상황에서 좋은 방법 중 하나가 선 그래프를 그리는 것이다. Seaborn에서는 lineplot() 메소드를 통해 이를 구현할 수 있으며 lineplot() 명령어를 직접 입력하든, relplot() 을 하고 kind = "line" 을 인자로 입력해 구현하든 상관 없다.
df = pd.DataFrame(dict(time=np.arange(500), value=np.random.randn(500).cumsum())) g = sns.relplot(x="time", y="value", kind="line", data=df) g.fig.autofmt_xdate()
Python
Because lineplot() assumes that you are most often trying to draw y as a function of x, the default behavior is to sort the data by the x values before plotting. However, this can be disabled:
lineplot()은 대개 x 축이 변함과 그에 따른 y 값을 그린다는 걸 전제로 하고 있다. 그래서 도표를 구현하기 전에, 기본적으로 x 축에 들어갈 변수를 값에 따라 정렬한다. 그러나 아래처럼 표현하는 건 불가능하다 :
df = pd.DataFrame(np.random.randn(500, 2).cumsum(axis=0), columns=["x", "y"]) sns.relplot(x="x", y="y", sort=False, kind="line", data=df);
Python

Aggregation and representing uncertainty¶

불특정구간에 대한 데이터 결집과 표현에 대해서
More complex datasets will have multiple measurements for the same value of the x variable. The default behavior in seaborn is to aggregate the multiple measurements at each x value by plotting the mean and the 95% confidence interval around the mean:
보다 복잡한 데이터셋은 x 축에 따른 y 값으로 하나가 아닌 다양한 값을 갖고 있을 수 있다. 이때 Seaborn의 기본 처리방식은 x 값에 따라 나타난 다양한 값들을 모아서 평균 낸 값들을 선으로 연결하고, 평균으로부터 95%의 신뢰구간을 색으로 표현하는 것이다.
fmri = sns.load_dataset("fmri") sns.relplot(x="timepoint", y="signal", kind="line", data=fmri);
Python
The confidence intervals are computed using bootstrapping, which can be time-intensive for larger datasets. It’s therefore possible to disable them:
그 신뢰구간은 부트스트래핑 기법을 사용해 계산된다. 데이터 셋이 커지면 부트스트래핑이란 게 시간을 오래 잡아먹기 때문에, 이 신뢰구간 계산 기능을 끄는 것도 가능하다.
sns.relplot(x="timepoint", y="signal", ci=None, kind="line", data=fmri);
Python
Another good option, especially with larger data, is to represent the spread of the distribution at each timepoint by plotting the standard deviation instead of a confidence interval:
특별히 큰 데이터에 처리함에 있어서 훌륭한 대안을 소개한다. 각 시점마다 (x 축) 데이터의 표준편차 안에 들어있는 데이터 분포를 표현하면서 신뢰구간 대신 사용하는 것이다.
sns.relplot(x="timepoint", y="signal", kind="line", ci="sd", data=fmri);
Python
To turn off aggregation altogether, set the estimator parameter to None. This might produce a strange effect when the data have multiple observations at each point.
여러 값을 대표 데이터로 표현하는 일련의 기능들을 모두 끄려면 estimator 매개변수를 None 으로 설정해주면 된다. 이런 선택은 한 시점마다 여러 y값을 갖는 데이터 표현할 때 흔히 쓰이는 방식이 아니기 때문에 굉장히 낯선 느낌을 줄 것이다.
sns.relplot(x="timepoint", y="signal", estimator=None, kind="line", data=fmri);
Python

Plotting subsets of data with semantic mappings¶

의미 구분을 통해 서브셋(subsets) 그래프 그리기
The lineplot() function has the same flexibility as scatterplot(): it can show up to three additional variables by modifying the hue, size, and style of the plot elements. It does so using the same API as scatterplot(), meaning that we don’t need to stop and think about the parameters that control the look of lines vs. points in matplotlib.
scatterplot()과 유사한 응용 기능을 lineplot() 도 갖고 있다. hue, size, style 총 3개의 추가적인 변수를 두고 의미 구분을 할 수 있다. 산점도와 동일한 API를 갖고 있기 때문에 가능한 일이며, 이 말인 즉슨 (Seaborn의 기반 시스템인) matplotlib의 선 그래프 그릴 때 필요한 매개변수에 대해서는 굳이 따로 고민하지 않아도 된다는 뜻이다.
주석 : hue를 통한 의미 구분을 해서 그래프를 그리면 그래프가 두 가지 이상이 동시에 그려지게 되는데, 그걸 Seaborn 도큐먼트는 서브셋(subsets) 이라고 표현하였다. 그래서 이번 소챕터 주제에 subsets 라는 말이 들어간다.
Using semantics in lineplot() will also determine how the data get aggregated. For example, adding a hue semantic with two levels splits the plot into two lines and error bands, coloring each to indicate which subset of the data they correspond to.
이러한 의미 구분 변수(hue, size, style)를 선 그래프에서 쓰면, 마찬가지로 어떻게 데이터를 응집할지가 결정된다. 예를 들어, hue 의미 구분 변수를 통해 2개로 데이터를 나눠 표현하면 2개의 선과 오차 밴드 (앞서 언급한 신뢰구간이나 표준편차를 표현한 색 구분 띠) 가 나타난다. 이 둘은 각각 색깔을 달리하여 어떤 데이터에 대응해 표현했는지를 구분한다.
sns.relplot(x="timepoint", y="signal", hue="event", kind="line", data=fmri);
Python
Adding a style semantic to a line plot changes the pattern of dashes in the line by default:
style 의미 변수를 선 그래프에 추가한다면 선을 그리는 방식 (주석 : 점선이냐 파선이냐 등의 dash 개념)의 패턴을 달리하게 된다. 딱히 지정해 주지 않는다면 클래스의 기본 세팅을 바탕으로 style이 결정된다.
sns.relplot(x="timepoint", y="signal", hue="region", style="event", kind="line", data=fmri);
Python
But you can identify subsets by the markers used at each observation, either together with the dashes or instead of them:
하지만 여러 그래프들을 마커의 모양을 달리하여 표현도 가능하다. 마커 스타일은 선의 스타일과 함께 쓸 수도 있고, 선 스타일 대신에 마커 스타일로 대신할 수도 있다.
sns.relplot(x="timepoint", y="signal", hue="region", style="event", dashes=False, markers=True, kind="line", data=fmri);
Python
As with scatter plots, be cautious about making line plots using multiple semantics. While sometimes informative, they can also be difficult to parse and interpret. But even when you are only examining changes across one additional variable, it can be useful to alter both the color and style of the lines. This can make the plot more accessible when printed to black-and-white or viewed by someone with color blindness:
산점도와 더불어 선 그래프를 여러 변수를 통한 구분(hue와 같은 것)을 사용해 쓸 때는 주의해야할 사항이 있다. 그 기법은 유익할 때도 있는 반면, 종종 파악이 더 어려워 질 수도 있다. 비록 단순한 변화량만을 의미구분 기법으로 표기하고 싶더라도 색깔 변화(hue)와 스타일 변화(markers나 dashes)를 둘 다 써보자. 이 방식은 흑백 출력 혹은 색맹과 같은 상황에 놓였을 때 그래프에 대한 접근성을 높일 수 있다.
sns.relplot(x="timepoint", y="signal", hue="event", style="event", kind="line", data=fmri);
Python
When you are working with repeated measures data (that is, you have units that were sampled multiple times), you can also plot each sampling unit separately without distinguishing them through semantics. This avoids cluttering the legend:
특정 기간 동안 지속적으로, 여러 샘플을 측정해 작업하고 있다면 굳이 hue와 같은 의미 구분 기법(semantic)으로 구분하는 게 아니라, 각 측정 값을 일일이 그래프로 찍는 방법도 있다. 이 방식은 범례를 쓰면서 데이터를 군집화해서 표현하는 방법과는 다른 방법이다.
( 역주 : 바로 앞에서 살펴본 기법은 여러 샘플을 하나의 변수에 포함시킨 뒤 신뢰구간과 같은 오차밴드로 묶어 표현하고 그걸 범례에 표기한 기법이었다.)
sns.relplot(x="timepoint", y="signal", hue="region", units="subject", estimator=None, kind="line", data=fmri.query("event == 'stim'"));
Python
The default colormap and handling of the legend in lineplot() also depends on whether the hue semantic is categorical or numeric:
hue를 통해 구분(semantic)하고자 하는 데이터가 명목 범인지 수치화된 데이터인지에 따라 표기하는 그래프의 색상이나 범례 구성이 달라진다.
dots = sns.load_dataset("dots").query("align == 'dots'") sns.relplot(x="time", y="firing_rate", hue="coherence", style="choice", kind="line", data=dots);
Python
It may happen that, even though the hue variable is numeric, it is poorly represented by a linear color scale. That’s the case here, where the levels of the hue variable are logarithmically scaled. You can provide specific color values for each line by passing a list or dictionary:
hue에 따른 구분 대상이 비록 (명목 범주가 아닌) 수치화 데이터일지라도, 그 데이터의 스케일에 따라 hue 구분의 효과가 형편 없을 때가 있다. 아래는 그에 해당하는 사례인데, 구분하고자 하는 변수 데이터의 스케일이 로그 함수를 따르는 스케일이었다. API에 리스트나 딕셔너리 타입으로 구체적인 색 구분을 부여함으로써 각각의 색을 표현해 줄 수도 있다.
palette = sns.cubehelix_palette(light=.8, n_colors=6) sns.relplot(x="time", y="firing_rate", hue="coherence", style="choice", palette=palette, kind="line", data=dots);
Python
Or you can alter how the colormap is normalized:
이렇게 하거나 색 구분을 정규화하는 방식으로 바꿔볼 수 있다. (아래와 같이 LogNorm API를 사용)
from matplotlib.colors import LogNorm palette = sns.cubehelix_palette(light=.7, n_colors=6) sns.relplot(x="time", y="firing_rate", hue="coherence", style="choice", hue_norm=LogNorm(), kind="line", data=dots);
Python
The third semantic, size, changes the width of the lines:
(선의 색깔, 스타일에 이은) 세 번째의 의미 구분 변수인 size는 선의 두께를 바꾼다 :
sns.relplot(x="time", y="firing_rate", size="coherence", style="choice", kind="line", data=dots);
Python
While the size variable will typically be numeric, it’s also possible to map a categorical variable with the width of the lines. Be cautious when doing so, because it will be difficult to distinguish much more than “thick” vs “thin” lines. However, dashes can be hard to perceive when lines have high-frequency variability, so using different widths may be more effective in that case:
선의 두께(size)에 의한 구분은 대개 수치화된 변수일 때 쓰이지만, 명목 변수일 때도 선의 두께를 변화시켜 구분해 표현할 수 있다. 그때는 다음과 같은 사항을 주의해야한다. 선이 더 얇은지 두꺼운지를 구분하는 것 자체가 쉽지 않기 때문이다. 하지만 지금과 같이 그래프 선들이 큰 변동성을 갖는 상황에서는 파선과 같이 dash를 넣는 기법(즉 style을 통한 의미 구분)은 파악하기 더 어려워진다. 그땐 두께를 달리하는 게 더 효과적이라 볼 수 있다.
sns.relplot(x="time", y="firing_rate", hue="coherence", size="choice", palette=palette, kind="line", data=dots);
Python

Plotting with date data¶

날짜 시간 데이터 도표로 그리기
Line plots are often used to visualize data associated with real dates and times. These functions pass the data down in their original format to the underlying matplotlib functions, and so they can take advantage of matplotlib’s ability to format dates in tick labels. But all of that formatting will have to take place at the matplotlib layer, and you should refer to the matplotlib documentation to see how it works:
선 그래프들은 대개 실제 날짜와 시간의 흐름과 함께 시각화가 진행된다. 이때 Seaborn은 기반이 되는 matplotlib 패키지의 클래스에 데이터를 넘겨 줌으로써 구현한다. 그래서 손쉽게 matplotlib가 시간 데이터를 tick lables(만약 x 축에 시간을 둔다면 x축에 배열하는 시간 데이터들을 tick labels라 명명함) 로 전환하는 게 가능하다. 그러나 그렇게 구현된 모든 도표의 형식이 결국 matplotlib를 따라가기 때문에, 작업시 matplotlib의 공식문서를 참고하길 권장한다.
df = pd.DataFrame(dict(time=pd.date_range("2017-1-1", periods=500), value=np.random.randn(500).cumsum())) g = sns.relplot(x="time", y="value", kind="line", data=df) g.fig.autofmt_xdate()
Python
/Users/mwaskom/miniconda3/envs/seaborn-py37-latest/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py:103: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters. To register the converters: >>> from pandas.plotting import register_matplotlib_converters >>> register_matplotlib_converters() warnings.warn(msg, FutureWarning)
Python

Showing multiple relationships with facets

파셋 개념을 이용해 여러 관계들을 표현하기
We’ve emphasized in this tutorial that, while these functions can show several semantic variables at once, it’s not always effective to do so. But what about when you do want to understand how a relationship between two variables depends on more than one other variable?
이 튜토리얼을 통해, 지금까지 배운 기능들이 hue와 같은 의미 변수(semantics) 추가로 한번에 여러 정보를 전달할 수 있다는 걸 확인했다. 물론 그게 언제나 유용하다는 것은 아니었지만... 자, 만약 관찰하고자 하는 2개의 변수가 제 3의 변수에 의해서 (그것이 하나든 여럿이든) 영향을 받아 어떤 관계를 보이는지 궁금하다면 어떻게 해야하나?
The best approach may be to make more than one plot. Because relplot() is based on the FacetGrid, this is easy to do. To show the influence of an additional variable, instead of assigning it to one of the semantic roles in the plot, use it to “facet” the visualization. This means that you make multiple axes and plot subsets of the data on each of them:
가장 좋은 방법은 아마 한 개의 도표를 더 그리는 것이다. 왜냐하면 relplot() FacetGrid 기능을 기반으로 하기 때문에 도표 하나 더 그리는 것 정도야 쉽기 때문이다. 추가적인 변수에 의한 영향을 표현하기 위해서는 의미 구분을 기존 그래프에 추가하기 보다는, 파셋facet을 통해 시각화해보자. 그 말인 즉슨, 여러 개의 도표를 그려서 각각의 도표에 데이터를 나눠서 표현하는 것이다.
# col = 'time' 이라고 파라미터를 줘서 칼럼 방향(가로로)으로 여러 도표를 그리게 했다 sns.relplot(x="total_bill", y="tip", hue="smoker", col="time", data=tips);
Python
You can also show the influence two variables this way: one by faceting on the columns and one by faceting on the rows. As you start adding more variables to the grid, you may want to decrease the figure size. Remember that the size FacetGrid is parameterized by the height and aspect ratio of each facet:
2개의 변수가 영향을 받는 건 이런 방식으로도 표현이 가능하다 : 하나는 칼럼 방향으로 도표를 여럿 그리고, 또 하나는 로우 방향으로 도표들을 그리는 것이다. 점점 더 많은 변수들을 그 속에 추가하다 보면, 공간이 부족해 각각의 그래프들의 크기는 줄어드는 걸 원할 수 있다. 이때 FacetGridheight 파라미터를 갖고 있음을 기억하면 된다. (그래프들의 좌우 비율은 height에 맞게 자동 조정됨 - aspect ratio)
sns.relplot(x="timepoint", y="signal", hue="subject", col="region", row="event", height=3, kind="line", estimator=None, data=fmri);
Python
When you want to examine effects across many levels of a variable, it can be a good idea to facet that variable on the columns and then “wrap” the facets into the rows:
여러 단계를 가진 변수에 걸쳐 나타나는 영향을 시각적으로 파악하고 싶다면, 그 변수를 col 인자의 매개변수로(col = "subject")놓아보자. "래핑wrap" 기능을 통해 그 단계에 해당하는 그래프를 정해 둔 갯수만큼 로우row 방향으로 정렬시켜 표현할 수 있다.
(주석 : col_wrap = 5 로 지정하면 5의 배수들 만큼 각 row마다 그래프를 배치한다는 뜻)
sns.relplot(x="timepoint", y="signal", hue="event", style="event", col="subject", col_wrap=5, height=3, aspect=.75, linewidth=2.5, kind="line", data=fmri.query("region == 'frontal'"));
Python
These visualizations, which are often called “lattice” plots or “small-multiples”, are very effective because they present the data in a format that makes it easy for the eye to detect both overall patterns and deviations from those patterns. While you should make use of the flexibility afforded by scatterplot() and relplot(), always try to keep in mind that several simple plots are usually more effective than one complex plot.
"격자lattice 도표" 혹은 "소형-다중 도표 small - multiples"라 불리는 이러한 시각화 기법은 시각적으로 전체적인 패턴들과 각 패턴들이 나타나는 차이들을 모두 쉽게 감지할 수 있기 때문에 매우 효과적이다. scatterplot()relplot() 들의 (hue와 같은 의미 구분 기법 등을 통한) 유연한 기능성을 잘 활용하는 것도 중요하나, 복잡한 도표를 그리는 것보다는 단순한 도표를 여러개 그리는 게 더 효과적이라는 걸 늘 명심하길 바란다.