Skip to content

PyGWalker 컴포넌트 API

drag-and-drop 탐색기만 사용하는 대신 Python 메서드 체인으로 PyGWalker 차트를 만들고 싶다면 pygwalker.component(...)를 사용하세요.

import pygwalker as pyg
 
chart = (
    pyg.component(df, spec_path="./gw_config.json", computation="browser")
    .bar()
    .encode(x="category", y="sum(revenue)", color="region")
    .layout(width=720, height=420)
)
 
html = chart.to_html()

팩토리

pyg.component(
    dataset,
    *,
    field_specs=None,
    spec="",
    spec_path=None,
    spec_io_mode="rw",
    theme_key="vega",
    appearance="media",
    show_cloud_tool=False,
    computation=None,
    kernel_computation=None,
    kanaries_api_key="",
    **kwargs,
) -> Component

dataset은 pandas DataFrame, polars DataFrame, pyarrow Table, 데이터베이스 Connector 또는 connector 스타일 문자열일 수 있습니다.

로컬 차트 상태 파일에는 spec_path를 사용하세요. 새 코드에는 computation을 사용하세요. kernel_computation은 레거시이며 PyGWalker 0.7.0에서 제거될 예정입니다.

Mark 메서드

Mark 메서드는 복사된 Component를 반환하므로 체인을 안전하게 재사용할 수 있습니다.

메서드차트 mark
.bar()Bar
.line()Line
.area()Area
.trail()Trail
.scatter()Point/scatter
.circle()Circle
.tick()Tick
.rect()Rect
.arc()Arc
.text()Text
.box()Box plot
.table()Table
.poi()Geographic point of interest

인코딩

.encode(...)를 사용해 필드를 시각 채널에 매핑하세요.

chart = (
    pyg.component(df)
    .scatter()
    .encode(
        x="ad_spend",
        y="revenue",
        color="channel",
        size="sum(orders)",
    )
)

지원 채널:

encode(
    x="",
    y="",
    color="",
    opacity="",
    size="",
    shape="",
    radius="",
    theta="",
    longitude="",
    latitude="",
    geoid="",
    details="",
    text="",
)

xy는 필드 목록도 받을 수 있습니다. sum(revenue) 같은 집계식은 Graphic Walker 집계 모델을 사용합니다.

레이아웃과 모드

.layout(...)으로 차트 크기와 레이아웃 옵션을 설정하세요.

chart = chart.layout(mode="fixed", width=640, height=360)

렌더링 모드는 다음 메서드로 전환합니다.

메서드용도
.profiling()프로파일링/테이블 모드를 렌더링합니다.
.explorer()현재 차트 상태를 감싼 전체 탐색기를 렌더링합니다.
.copy()차트 체인을 분기하기 전에 명시적으로 복사합니다.
.to_html()현재 컴포넌트의 HTML을 반환합니다.

정적 내보내기 제한

컴포넌트 .to_html()은 정적 HTML입니다. 탐색기 및 프로파일링 컴포넌트 내보내기는 라이브 kernel/cloud 계산을 거부합니다.

# Use browser computation when exporting component HTML.
component = pyg.component(df, computation="browser")
html = component.explorer().to_html()

차트에 kernel 또는 cloud 계산이 필요하면 노트북 API, Streamlit, Gradio 같은 라이브 어댑터를 사용하세요.

관련 가이드