콘텐츠로 이동

hossam.my_plot

hossam.my_plot

init

init(
    width=1280,
    height=640,
    rows=1,
    cols=1,
    title=None,
    xlabel=None,
    ylabel=None,
    grid=True,
    twinx=False,
)

그래프의 크기와 dpi를 설정하여 fig와 ax 객체를 반환하는 함수

Parameters:

Name Type Description Default
- width

그래프의 가로 크기 (픽셀 단위)

required
- height

그래프의 세로 크기 (픽셀 단위)

required
- rows

그래프의 행 수

required
- cols

그래프의 열 수

required
- title

그래프의 제목 (기본값: None)

required
- xlabel

x축 레이블 (기본값: None)

required
- ylabel

y축 레이블 (기본값: None)

required
- grid

그래프에 그리드를 표시할지 여부 (기본값: True)

required
- twinx

y축이 2개인 그래프를 그릴 때, 두 번째 y축을 생성할지 여부 (기본값: False)

required

Returns:

Type Description
  • fig: 생성된 Figure 객체
  • ax: 생성된 Axes 객체 또는 Axes 배열

show

show(save_path=None)

그래프를 화면에 표시하는 함수

Parameters:

Name Type Description Default
- grid

그리드를 표시할지 여부 (기본값: True)

required
- save_path

그래프를 저장할 파일 경로. None이면 저장하지 않음.

required

lineplot

lineplot(
    data=None,
    x=None,
    y=None,
    hue=None,
    title=None,
    xlabel=None,
    ylabel=None,
    color=None,
    linewidth=2.0,
    linestyle="-",
    palette=None,
    marker=None,
    markersize=None,
    markeredgewidth=None,
    markeredgecolor=None,
    markerfacecolor=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

선 그래프(lineplot)를 그린다.

Parameters:

Name Type Description Default
data

시각화할 데이터.

None
x

x축 값 컬럼명.

None
y

y축 값 컬럼명.

None
hue

범주 구분 컬럼명.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
color

선 색상 (hue가 없을 때 적용).

None
linewidth

선 굵기.

2.0
linestyle

선 스타일.

'-'
palette

색상 팔레트 이름.

None
marker

마커 모양.

None
markersize

마커 크기.

None
markeredgewidth

마커 테두리 두께.

None
markeredgecolor

마커 테두리 색상.

None
markerfacecolor

마커 내부 색상.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

pointplot

pointplot(
    data=None,
    x=None,
    y=None,
    hue=None,
    order=None,
    hue_order=None,
    estimator="mean",
    errorbar="se",
    capsize=0.1,
    dodge=False,
    markers="o",
    linestyles="-",
    palette=None,
    color=None,
    title=None,
    xlabel=None,
    ylabel=None,
    legend_title=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

점 그래프(pointplot)를 그린다. 범주별 추정치(기본: 평균)와 오차범위를 점과 선으로 표현하므로 분산분석의 상호작용 플롯(interaction plot) 등에 활용한다.

Parameters:

Name Type Description Default
data

시각화할 데이터.

None
x

x축 범주 컬럼명.

None
y

y축 값 컬럼명.

None
hue

범주 구분 컬럼명.

None
order

x축 범주의 표시 순서.

None
hue_order

hue 범주의 표시 순서.

None
estimator

각 범주의 대표값 추정 방법 (기본 'mean').

'mean'
errorbar

오차범위 표현 방식 (예: 'se', 'sd', ('ci', 95)).

'se'
capsize

오차범위 막대 끝 모자의 크기.

0.1
dodge

hue별 점이 겹치지 않도록 좌우로 분리할지 여부 또는 분리 폭.

False
markers

점 마커 모양.

'o'
linestyles

선 스타일.

'-'
palette

색상 팔레트 이름.

None
color

단일 색상 (hue가 없을 때 사용).

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
legend_title

범례 제목 (hue가 있을 때 표시).

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

kdeplot

kdeplot(
    data=None,
    x=None,
    hue=None,
    meanline=False,
    clevel=0,
    title=None,
    xlabel=None,
    ylabel=None,
    fill=False,
    linewidth=2.0,
    palette=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

단변량 커널 밀도 그래프를 그린다. hue가 지정된 경우 범주별 평균선을 함께 표시한다.

Parameters:

Name Type Description Default
data

시각화할 데이터.

None
x

x축 컬럼명 혹은 x축 값 시퀀스.

None
hue

범주 구분 컬럼명.

None
meanline

평균선 표시 여부.

False
clevel

모평균 신뢰구간을 표시할 신뢰수준. 0이면 표시하지 않는다 (기본값: 0).

0
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
fill

면적 채우기 여부.

False
linewidth

선 굵기.

2.0
palette

색상 팔레트 이름.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

histplot

histplot(
    data=None,
    x=None,
    bins="auto",
    hue=None,
    title=None,
    xlabel=None,
    ylabel=None,
    linewidth=1,
    palette=None,
    kde=False,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

히스토그램을 그린다.

Parameters:

Name Type Description Default
data

시각화할 데이터.

None
x

히스토그램 대상 컬럼명.

None
bins

구간 수 또는 경계.

'auto'
hue

범주 컬럼명.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
linewidth

선 굵기.

1
palette

색상 팔레트 이름.

None
kde

커널 밀도 그래프 겹쳐 그릴지 여부.

False
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

boxplot

boxplot(
    data=None,
    x=None,
    y=None,
    hue=None,
    orient=None,
    palette=None,
    order=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

상자그림(boxplot)을 그린다.

Parameters:

Name Type Description Default
data

시각화할 데이터.

None
x

x축 범주 컬럼명.

None
y

y축 값 컬럼명.

None
hue

범주 구분 컬럼명.

None
orient

상자그림 방향 (None, 'v' 또는 'h').

None
palette

색상 팔레트 이름.

None
order

상자그림 순서를 의미하는 연속형 자료형.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

violinplot

violinplot(
    data=None,
    x=None,
    y=None,
    hue=None,
    orient=None,
    palette=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

바이올린 플롯을 그린다.

Parameters:

Name Type Description Default
data

시각화할 데이터.

None
x

x축 범주 컬럼명.

None
y

y축 값 컬럼명.

None
hue

범주 구분 컬럼명.

None
orient

바이올린 플롯 방향 (None, 'v' 또는 'h').

None
palette

색상 팔레트 이름.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

heatmap

heatmap(
    data=None,
    annot=True,
    fmt="0.2f",
    linewidths=0.5,
    palette=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

히트맵을 그린다.

Parameters:

Name Type Description Default
data

시각화할 데이터 (2차원 배열 또는 DataFrame).

None
annot

셀에 값 표시 여부.

True
fmt

셀에 표시할 값의 형식.

'0.2f'
linewidths

셀 간격 선 두께.

0.5
palette

색상 팔레트 이름.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

barplot

barplot(
    data=None,
    x=None,
    y=None,
    hue=None,
    estimator=np.mean,
    order=None,
    palette=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

막대그래프를 그린다

Parameters:

Name Type Description Default
data

시각화할 데이터 (2차원 배열 또는 DataFrame).

None
x

x축 범주 컬럼명.

None
y

y축 값 컬럼명.

None
hue

범주 구분 컬럼명.

None
estimator

막대 높이 계산 함수 (기본값: np.mean).

mean
order

정렬 순서를 의미하는 연속형 자료형.

None
palette

색상 팔레트 이름.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

countplot

countplot(
    data=None,
    x=None,
    y=None,
    hue=None,
    order=None,
    palette=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

빈도 그래프를 그린다

Parameters:

Name Type Description Default
data

시각화할 데이터 (2차원 배열 또는 DataFrame).

None
x

x축 범주 컬럼명.

None
y

y축 값 컬럼명.

None
hue

범주 구분 컬럼명.

None
order

정렬 순서를 의미하는 연속형 자료형.

None
palette

색상 팔레트 이름.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

pieplot

pieplot(
    x,
    labels,
    autopct="%0.1f%%",
    startangle=90,
    counterclock=False,
    explode=None,
    donutchart=False,
    wedge_width=0.7,
    wedge_color="#ffffff",
    wedge_linewidth=3,
    palette=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

파이 그래프 혹은 도넛 그래프를 그린다

Parameters:

Name Type Description Default
x

x축 범주 컬럼명.

required
labels

파이 조각에 대한 라벨.

required
autopct

퍼센트 표시 형식.

'%0.1f%%'
startangle

시작 각도.

90
counterclock

시계 반대 방향으로 그릴지 여부.

False
explode

조각 간격.

None
donutchart

도넛 차트 여부.

False
wedge_width

도넛 차트일 때 조각 너비 비율.

0.7
wedge_color

도넛 차트일 때 조각 사이 경계선 색상.

'#ffffff'
wedge_linewidth

도넛 차트일 때 조각 사이 경계선 굵기.

3
palette

색상 팔레트 이름.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

stackplot

stackplot(
    data,
    x,
    y,
    hue,
    aggfunc=np.sum,
    orient="v",
    ratio=False,
    text=True,
    text_color="#ffffff",
    text_fontsize=12,
    text_format=None,
    palette=None,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

누적 막대그래프를 그린다

Parameters:

Name Type Description Default
data

시각화할 데이터.

required
x

x축 범주 컬럼명.

required
y

y축 값 컬럼명.

required
hue

범주 구분 컬럼명.

required
aggfunc

누적할 값 계산 함수 (기본값: np.sum).

sum
orient

막대 방향 ('v' 또는 'h').

'v'
ratio

누적값을 비율로 표시할지 여부.

False
text

누적값 텍스트 표시 여부.

True
text_color

누적값 텍스트 색상.

'#ffffff'
text_fontsize

누적값 텍스트 폰트 크기.

12
palette

색상 팔레트 이름.

None
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

scatterplot

scatterplot(
    data,
    x,
    y,
    hue=None,
    marker="o",
    color=None,
    size=100,
    edgecolor="#ffffff",
    linewidth=1.5,
    alpha=1,
    palette="tab10",
    outline=True,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    ax=None,
    **params
)

산점도를 그린다

Parameters:

Name Type Description Default
data

시각화할 데이터.

required
x

x축 값 컬럼명.

required
y

y축 값 컬럼명.

required
hue

범주 구분 컬럼명.

None
marker

마커 모양 (기본값: "o").

'o'
color

마커 색상 (hue가 None일 때 적용).

None
size

마커 크기 (기본값: 100).

100
edgecolor

마커 테두리 색상 (기본값: "#ffffff").

'#ffffff'
linewidth

마커 테두리 두께 (기본값: 1.5).

1.5
alpha

마커 투명도 (0~1, 기본값: 1).

1
palette

색상 팔레트 이름.

'tab10'
outline

ConvexHull로 외곽선 그릴지 여부. hue가 지정되었을 때만 작동 (기본값: True).

True
title

그래프 제목.

None
xlabel

x축 레이블.

None
ylabel

y축 레이블.

None
width

캔버스 가로 픽셀.

1280
height

캔버스 세로 픽셀.

640
save_path

이미지 저장 경로.

None
ax

그래프를 그릴 Axes 객체. None이면 init 함수로 새로 생성.

None

plot_hull

plot_hull(data, x, y, hue, palette, ax)

ConvexHull을 이용하여 각 군집의 외곽선을 그리는 함수

Parameters:

Name Type Description Default
data

시각화할 데이터.

required
x

x축 값 컬럼명.

required
y

y축 값 컬럼명.

required
hue

범주 구분 컬럼명.

required
palette

색상 팔레트 이름.

required
ax

ConvexHull로 외곽선을 그릴 Axes 객체.

required

lmplot

lmplot(
    data,
    x,
    y,
    hue=None,
    palette=None,
    col=None,
    row=None,
    markers="o",
    scatter_edgecolor="#ffffff",
    scatter_linewidths=1,
    scatter_size=50,
    scatter_alpha=0.8,
    linestyle="-",
    linecolor=None,
    linewidth=2,
    title=None,
    xlabel=None,
    ylabel=None,
    width=1280,
    height=640,
    save_path=None,
    **params
)

seaborn lmplot으로 산점도 그래프와 회귀선을 시각화 한다.

Parameters:

Name Type Description Default
data DataFrame

시각화할 데이터.

required
x str

독립변수 컬럼.

required
y str

종속변수 컬럼.

required
hue str | None

범주 컬럼.

None
palette str | None

팔레트 이름.

None
col str | None

열 패싯 컬럼.

None
row str | None

행 패싯 컬럼.

None
markers str | list[str]

산점도 점 모양.

'o'
scatter_edgecolor str | None

산점도 점 외곽선 색상.

'#ffffff'
scatter_linewidths float

산점도 점 외곽선 굵기

1
scatter_size int

산점도 점 크기.

50
scatter_alpha float

산점도 점 투명도.

0.8
linestyle str

회귀선 스타일.

'-'
linecolor str | None

회귀선 색상.

None
linewidth float

회귀선 굵기.

2
title str | None

그래프 제목.

None
xlabel str | None

x축 레이블.

None
ylabel str | None

y축 레이블.

None
width int

캔버스 가로 픽셀.

1280
height int

캔버스 세로 픽셀.

640
save_path str | None

이미지 저장 경로. None이면 화면에 표시.

None

Returns:

Type Description

None

pairplot

pairplot(
    data,
    x=None,
    y=None,
    hue=None,
    palette=None,
    diag_kind="kde",
    reg=False,
    markers="o",
    scatter_size=20,
    scatter_alpha=0.8,
    linecolor=None,
    linewidth=1.5,
    linestyle="-",
    title=None,
    width=1280,
    height=640,
    save_path=None,
    **params
)

산점도 행렬 시각화

Parameters:

Name Type Description Default
data DataFrame

시각화할 데이터.

required
x str | list[str] | None

대상 컬럼명 혹은 컬럼명 리스트

None
y str | list[str] | None

대상 컬럼명 혹은 컬럼명 리스트

None
hue str | None

범주 컬럼명.

None
palette str | None

팔레트 이름.

None
diag_kind str

대각선에 표시할 그래프 종류. 'hist' 또는 'kde'.

'kde'
reg bool

회귀선 표시 여부.

False
markers str | list[str]

산점도 점 모양.

'o'
scatter_size int

산점도 점 크기.

20
scatter_alpha float

산점도 점 투명도.

0.8
linecolor str | None

회귀선 색상.

None
linewidth float

회귀선 굵기.

1.5
linestyle str

회귀선 스타일.

'-'
title str | None

그래프 제목.

None
width int

캔버스 가로 픽셀.

1280
height int

캔버스 세로 픽셀.

640
save_path str | None

이미지 저장 경로. None이면 화면에 표시.

None