이 멋 진 도표 이기 pyecharts 를 배 워 서 회사 에서 중용 되 지 않 을 까 봐?

설치 하 다
우선 pyecharts 를 설치 해 야 합 니 다.pip 명령 을 통 해 직접 설치 하면 됩 니 다.

pip install pyecharts
설치 가 완료 되면 pip list 명령 을 통 해 python 이 설치 한 라 이브 러 리 목록 을 볼 수 있 습 니 다.pyecharts 설치 버 전과 설치 성공 여 부 를 봅 니 다.
在这里插入图片描述
가 져 오기 모듈
낡은 규칙 은 이야기 의 순 조로 운 발전 을 위해 우 리 는 먼저 본문 에 필요 한 모듈 을 도입 할 수 있다.

from pyecharts.charts import Bar
from pyecharts.charts import Pie
from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.charts import EffectScatter
from pyecharts.globals import SymbolType
from pyecharts.charts import Grid
from pyecharts.charts import WordCloud
from pyecharts.charts import Map
import random
주:아래 도표 생 성 은 모두 Jupyter Notebook 환경 에서 이 루어 집 니 다.
3.막대 그래프
평소에 우리 가 가장 많이 본 것 은 기둥 모양 의 그림 이 고 pyecharts 가 기둥 모양 의 그림 을 만 드 는 것 도 매우 간단 하 다.x 축 과 y 축의 데 이 터 를 직접 채 우 면 됩 니 다.

x = ['1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ', '10 ', '11 ', '12 ']
data_china = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
data_russia = [1.6, 5.4, 9.3, 28.4, 22.7, 60.7, 162.6, 199.2, 56.7, 43.8, 3.0, 4.9]

bar = Bar()
bar.add_xaxis(x)
bar.add_yaxis("   ", data_china)
bar.set_global_opts(title_opts=opts.TitleOpts(title="Bar -     "))
bar.rerender_notebook()
run 프로그램 을 실행 하면 다음 과 같은 막대 그래프 를 얻 을 수 있 습 니 다.
在这里插入图片描述
물론 pyecharts 는 체인 호출 도 지원 합 니 다.실 현 된 기능 이 일치 합 니 다.코드 는 다음 과 같 습 니 다.

bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis('china', data_china)
    .set_global_opts(title_opts=opts.TitleOpts(title="Bar -     "))
)
bar.render_notebook()
그 밖 에 하나의 기둥 모양 그림 에 여러 개의 y 축 기록 을 추가 하여 여러 개의 기둥 모양 대 비 를 실현 할 수 있 습 니 다.한 번 만 더 add 를 호출 하면 됩 니 다.yaxis 면 됩 니 다.

bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis('china', data_china)
    .add_yaxis("sussia", data_russia)
    .set_global_opts(title_opts=opts.TitleOpts(title="Bar -     "))
)
bar.render_notebook()
在这里插入图片描述
때때로 기둥 모양 의 그림 이 너무 높 아서 보기 불편 하고 우 리 는 x 축 과 y 축 을 교환 하여 가로의 기둥 모양 의 그림 을 생 성 할 수 있다.다 중 막대 그래프 와 xy 축 이 서로 바 뀌 지 않 고 중첩 사용 할 수 있 습 니 다.

bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis('china', data_china)
    .add_yaxis('russia', data_russia)
    .reversal_axis()
    .set_series_opts(label_opts=opts.LabelOpts(position="right"))
    .set_global_opts(title_opts=opts.TitleOpts(title="Bar -    XY  "))
)
bar.render_notebook()
在这里插入图片描述
떡 모양 그림
떡 모양 그림 도 사용 빈도 가 높 은 도표 중 하나 로 특히 백분율 류 에 적용 되 는 그림 은 각 유형 이 전체 점유 율 을 차지 하 는 비례 를 직관 적 으로 알 수 있다.

pie = (
    Pie()
    .add("", [list(z) for z in zip(x, data_china)])
    .set_global_opts(title_opts=opts.TitleOpts(title="    "))
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
pie.render_notebook()
在这里插入图片描述
링 그래프

pie = (
    Pie(init_opts=opts.InitOpts(width="600px", height="400px"))
    .add(
        series_name="   ",
        data_pair=[list(z) for z in zip(x, data_china)],
        radius=["50%", "70%"],
        label_opts=opts.LabelOpts(is_show=False, position="center"),
    )
    .set_global_opts(legend_opts=opts.LegendOpts(pos_left="legft", orient="vertical"))
    .set_series_opts(
        tooltip_opts=opts.TooltipOpts(
            trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"
        ),
    label_opts=opts.LabelOpts(formatter="{b}: {c}")
    )
)
pie.render_notebook()
在这里插入图片描述
5.접선 도
접 는 선 도 는 보통 데이터 가 서로 다른 시간 대의 추 세 를 보 여 주 는 것 이다.예 를 들 어 비교적 전형 적 인 주식시장 K 선 도 는 바로 접 는 그림 의 일종 이다.

line = (
    Line()
    .add_xaxis(x)
    .add_yaxis('china', data_china)
    .set_global_opts(title_opts=opts.TitleOpts(title="     "))
)
line.render_notebook()
在这里插入图片描述
마찬가지 로 기둥 모양 그림 과 유사 하 며 접 는 선 그림 도 한 그림 에 여러 개의 Y 축 기록 을 추가 할 수 있다.

line = (
    Line()
    .add_xaxis(x)
    .add_yaxis('china', data_china)
    .add_yaxis('russis', data_russia)
    .set_global_opts(title_opts=opts.TitleOpts(title="    "))
)
line.render_notebook()
在这里插入图片描述
물론 계단 접 기 그림 도 있어 서 가능 합 니 다.

line = (
    Line()
    .add_xaxis(x)
    .add_yaxis('china', data_china, is_step=True)
    .set_global_opts(title_opts=opts.TitleOpts(title="     "))
)
line.render_notebook()
在这里插入图片描述
산 점도

scatter = (
    EffectScatter()
    .add_xaxis(x)
    .add_yaxis("", data_china)
    .set_global_opts(title_opts=opts.TitleOpts(title="     "))
)
scatter.render_notebook()
在这里插入图片描述
데이터 의 대비 가 뚜렷 하지 않 아서 우 리 는 산 점도 에 격자 를 더 해서 각 점 에 대응 하 는 y 축 데 이 터 를 더욱 뚜렷하게 볼 수 있다.

scatter = (
    EffectScatter()
    .add_xaxis(x)
    .add_yaxis("china", data_china, symbol=SymbolType.ARROW)
    .set_global_opts(
        title_opts=opts.TitleOpts(title="   -   "),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
)
scatter.render_notebook()
在这里插入图片描述
우 리 는 또한 정점 의 형상 을 가리 킬 수 있 고,또 하나의 산 점도 에 여러 개의 y 축 기록 을 추가 할 수 있다.이 배치 들 은 마치 블록 처럼 마음대로 쌓 여 있다.

scatter = (
    EffectScatter()
    .add_xaxis(x)
    .add_yaxis("china", [x + 30 for x in data_russia],symbol=SymbolType.ARROW)
    .add_yaxis("russia", data_russia, symbol=SymbolType.TRIANGLE) 
    .set_global_opts(
        title_opts=opts.TitleOpts(title="   -   "),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
)
scatter.render_notebook()
在这里插入图片描述
7.도표 합병
때때로 우 리 는 여러 가지 그림 을 한 장의 그림 에 집중 적 으로 표시 해 야 한다.pyechars 도 생각 했다.기본 적 인 절 차 는 각 유형의 그림 을 따로 만 든 다음 에 Grid 로 두 사람 을 합치 면 된다.
예 를 들 어 우 리 는 막대 그래프 와 접 는 선 도 를 함께 놓 으 려 면 먼저 Bar 와 Line 을 각각 생 성 한 다음 에 두 사람 을 합병 하면 된다.

from pyecharts.charts import Grid

bar = (
    Bar()
    .add_xaxis(x)
    .add_yaxis('china', data_china)
    .add_yaxis("sussia", data_russia)
    .set_global_opts(
        title_opts=opts.TitleOpts(title="    "),
    )
)

line = (
    Line()
    .add_xaxis(x)
    .add_yaxis("   ", [x + 50 for x in data_china]
    )
)

bar.overlap(line)
grid = Grid()
grid.add(bar, opts.GridOpts(pos_left="5%", pos_right="5%"), is_control_axis_index=True)
grid.render_notebook()
在这里插入图片描述
사운
pyechars 는 단어 구름 에 도 가능 하고 중국어 도 전혀 문제 가 없 으 며 난동 이 일어나 지 않 습 니 다.

import pyecharts.options as opts
from pyecharts.charts import WordCloud

data = [("    ", "999"),("    ", "888"),("    ", "777"),("      ", "688"),("      ", "588"),("    ", "516"),("    ", "515"),("    ", "483"),("     ", "462"),("    ", "449"),("       ", "429"),("    ", "407"),("       ", "406"),("    ", "406"),("      ", "386"),("       ", "385"),("    ", "375"),("    ", "355"),("      ", "355"),("    ", "335"),("    ", "324"),("      ", "304"),("       ", "304"),("    ", "284"),("     ", "284"),("  ", "284"),("    ", "254"),("        ", "254"),("    ", "253"),("      ", "253"),("    ", "223"),("       ", "223"),("    ", "223"),("    ", "223"),("    ", "223"),("    ", "223"),("    ", "223"),("    ", "223"),("    ", "223"),("    ", "152"),("    ", "152"),("    ", "152"),("    ", "152"),("    ", "152"),("    ", "152"),("  、   ", "152"),("    ", "152"),("    ", "112"),("    ", "112"),("      ", "112"),("       ", "112"),("    ", "112"),("    ", "112"),("      ", "112"),("      ", "92"),("      ", "92"),("    ", "92"),("    ", "92"),("        ", "92"),("    ", "92"),("      ", "72"),("        ", "72"),("    ", "72"),("      ", "72"),("    ", "71"),("    ", "71"),("  ", "71"),("  ", "71"),("      ", "71"),("     ", "71"),("    ", "71"),("    ", "71"),("    ", "71"),("    (  )  ", "71"),("      ", "71"),("    ", "71"),("      ", "71"),("     ", "71"),("    ", "41"),("      ", "41"),("      ", "41"),("    ", "41"),("    ", "41"),("    ", "41"),("    ", "41"),("    ", "41"),("      ", "41"),("       ", "41"),("    ", "21"),("  ", "21"),("    ", "21"),("    ", "21"),("      ", "21"),("    ", "21"),("    ", "21"),("    ", "11"),("    ", "11"),("    ", "11"),("      ", "11"),("  ", "11"),("    ", "11"),("  ", "11"),("       (       、    )", "11"),("    ", "11"),("    ", "11"),("    ", "11"),("    ", "11"),("    ", "11"),("      ", "11"),("       ", "11"),("    ", "11"),("     ", "11"),("      ", "11"),("    ", "11"),("    ", "11"),("  ", "11"),("    ", "11"),("        ", "11"),("      ", "11"),("  (  )  ", "11"),("       ", "11"),("    ", "11"),("    ", "11"),("    ", "11"),("        ", "11"),("     ", "11"),("       ", "11"),("    ", "11"),("           ", "11"),("    ", "11"),("    ", "11"),("       ", "11"),("      ", "11"),]

wordCloud = (
    WordCloud()
    .add(series_name="    ", data_pair=data, word_size_range=[6, 66])
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="    ", title_textstyle_opts=opts.TextStyleOpts(font_size=23)
        ),
        tooltip_opts=opts.TooltipOpts(is_show=True),
    )
)
在这里插入图片描述
지도
때때로 우 리 는 데 이 터 를 지도 에 전시 하 기 를 희망 한다.예 를 들 어 전국 전염병 상황,전국 각 성의 인구 데이터,위 챗 친구 각 성의 분포 등 이다.

provinces = ['  ', '  ', '  ', '  ', '  ', '  ', '  ', '   ', '  ', '  '] 
values = [random.randint(1, 1024) for x in range(len(provinces))]

map = (
    Map()
    .add("", [list(z) for z in zip(provinces, values)], "china")
    .set_global_opts(
        title_opts=opts.TitleOpts(title="      "),
        visualmap_opts=opts.VisualMapOpts(max_=1024, is_piecewise=True),
    )

)
map.render_notebook()
在这里插入图片描述
총화
오늘 우 리 는 pyecharts 를 통 해 몇 가지 상용 도 표를 그 렸 습 니 다.물론 도 표를 그 리 는 데 는 고정된 절차 가 있 습 니 다.
생 성 도 표 는 크게 세 단계 로 나 눌 수 있 으 며 관련 데 이 터 를 준비 하고 체인 호출 법 으로 데이터 와 관련 설정 을 설정 하 며 render 를 호출 할 수 있 습 니 다.notebook()또는 render()함수 생 성 도표.
이 멋 진 도표 이기 pyecharts 를 배 우 는 것 에 대해 회사 에서 중용 되 지 않 을 까 봐?의 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 python pyecharts 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!

좋은 웹페이지 즐겨찾기