Pyechart绘图基础

1.绘制散点图

from pyecharts.charts import Scatter
import pyecharts.options as opts
import numpy as np

x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
y2 = np.cos(x)

#绘制散点图
(Scatter()
 .add_xaxis(xaxis_data=x)
 .add_yaxis(series_name='sin', y_axis=y)
 .add_yaxis(series_name='cos', y_axis=y2, label_opts=opts.LabelOpts(is_show=False))
).render_notebook()

效果:

image-20220701104627795

2.绘制折线图

#绘制线图
from pyecharts.charts import Line
import pyecharts.options as opts

x=np.linspace(0,2*np.pi,100)
y=np.sin(x)

(
    Line()
    .add_xaxis(xaxis_data=x)
    .add_yaxis(series_name='sin', y_axis=y,label_opts=opts.LabelOpts(is_show=False))
    .add_yaxis(series_name='cos', y_axis=np.cos(x),label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(title_opts=opts.TitleOpts(title='曲线'),
                     tooltip_opts=opts.TooltipOpts(axis_pointer_type='cross')
                     )
).render_notebook()

效果:

image-20220701104644148

3.绘制饼图

#绘制饼图
from pyecharts.charts import Pie
import pyecharts.options as opts

num = [110, 136, 108, 48, 111, 112, 103]
lab = ['哈士奇', '萨摩耶', '泰迪', '金毛', '牧羊犬', '吉娃娃', '柯基']

(
    Pie(init_opts=opts.InitOpts(width='720px', height='320px'))
    .add(series_name='',
         data_pair=[(j, i) for i, j in zip(num, lab)]
        )
).render_notebook()

效果:

image-20220701104655009

4.绘制柱状图

#绘制柱状图
from pyecharts.charts import Bar
import pyecharts.options as opts

num = [110, 136, 108, 48, 111, 112, 103]
num2 = [90, 110, 101, 70, 90, 120, 99]
lab = ['哈士奇', '萨摩耶', '泰迪', '金毛', '牧羊犬', '吉娃娃', '柯基']

bar = (
    Bar(init_opts=opts.InitOpts(width='720px', height='320px'))
    .add_xaxis(xaxis_data=lab)
    .add_yaxis(series_name='商家A', y_axis=num)
    .add_yaxis(series_name='商家B', y_axis=num2)
    .set_global_opts(title_opts=opts.TitleOpts(title='各商家拥有的犬只数量统计情况', subtitle='如有雷同,纯属巧合'))
)

bar.render_notebook()

效果:

image-20220701104714772

5.绘制多图到一个页面

from pyecharts.charts import Scatter, Line, Grid
import pyecharts.options as opts
import numpy as np

x = np.linspace(0, 10, 50)
point = (Scatter()
         .add_xaxis(xaxis_data=x)
         .add_yaxis(series_name='', y_axis=np.sin(x), label_opts=opts.LabelOpts(is_show=False))  # 是否显示散点对应的数据(默认显示)
        )

line = (Line()
         .add_xaxis(xaxis_data=x)
         .add_yaxis(series_name='', y_axis=np.cos(x), label_opts=opts.LabelOpts(is_show=False))  # 是否显示散点对应的数据(默认显示)
        )

grid = (
        Grid(init_opts=opts.InitOpts(width="720px", height="320px"))
        .add(point, grid_opts=opts.GridOpts(pos_bottom="60%"))
        .add(line, grid_opts=opts.GridOpts(pos_top="60%"))
    )

grid.render_notebook()

效果:

image-20220701104726299

6.参考文章

Pyecharts制作地图的几种方法评析 - 知乎

Pyechart入门 - 简书

【创作不易,望点赞收藏,若有疑问,请留言,谢谢】

posted @ 2022-07-01 11:08  东血  阅读(884)  评论(0编辑  收藏  举报

载入天数...载入时分秒...