Python数据可视化——pyecharts可视化(一)

散点图:

from pyecharts.charts import *
import numpy as np
import pyecharts.options as opt

x = np.linspace(0,2*np.pi,50)
y = np.sin(x)
y2 = np.cos(x)
# 散点图
(Scatter(init_opts=opt.InitOpts(width='620px',height='320px'))
    .add_xaxis(xaxis_data=x)
    .add_yaxis(series_name='sin',y_axis=y)
    .add_yaxis(series_name='cos',y_axis=y2,label_opts=opt.LabelOpts(is_show=False))
).render_notebook()

Python数据可视化——pyecharts可视化(一)_第1张图片

线图:

# 线图
(Line()
    .add_xaxis(xaxis_data=x)
    .add_yaxis(series_name='sin',y_axis=y,label_opts=opt.LabelOpts(is_show=False))
    .set_global_opts(title_opts=opt.TitleOpts(title='曲线'),  # 设置标题
                    tooltip_opts=opt.TooltipOpts(axis_pointer_type='cross')
                    )    # 全局设置,
).render_notebook()

Python数据可视化——pyecharts可视化(一)_第2张图片

饼图、环图、玫瑰图:

# 饼图
num = [110, 136, 108, 48, 111, 112, 103]
lab = ['哈士奇', '萨摩耶', '泰迪', '金毛', '牧羊犬', '吉娃娃', '柯基']
(Pie(init_opts=opt.InitOpts(width='520px',height='262px'))
    .add(series_name='',data_pair=[(i,j) for i,j in zip(lab,num)])
).render_notebook()

Python数据可视化——pyecharts可视化(一)_第3张图片

 

# 环图
(Pie(init_opts=opt.InitOpts(width='720px',height='320px'))
    .add(series_name='',data_pair=[(i,j) for i,j in zip(lab,num)],radius=['40%','75%'])  # 40%是内半径,75%是外半径
).render_notebook()
 

Python数据可视化——pyecharts可视化(一)_第4张图片wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

# 玫瑰图
(Pie(init_opts=opt.InitOpts(width='720px',height='320px'))
    .add(series_name='',data_pair=[(i,j) for i,j in zip(lab,num)],rosetype='radius')  
).render_notebook()
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

Python数据可视化——pyecharts可视化(一)_第5张图片wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

直方图:

# 直方图
num = [110, 136, 108, 48, 111, 112, 103]
num2 = [90, 110, 101, 70, 90, 120, 99]
lab = ['哈士奇', '萨摩耶', '泰迪', '金毛', '牧羊犬', '吉娃娃', '柯基']
(Bar()
    .add_xaxis(xaxis_data=lab)
    .add_yaxis(series_name='一',yaxis_data=num)
    .add_yaxis(series_name='二',yaxis_data=num2)
    .set_global_opts(title_opts=opt.TitleOpts(title='犬类数据对比',subtitle='一和二'))  # 主标题和副标题
).render_notebook()
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

 

Python数据可视化——pyecharts可视化(一)_第6张图片

并行多图:

# 并行多图
x = np.linspace(0,2*np.pi,40)
y = np.sin(x)

lines = (
    Line()
    .add_xaxis(xaxis_data=x)
    .add_yaxis(series_name='',y_axis=y,label_opts=opt.LabelOpts(is_show=False))
)
points = (
    Scatter()
    .add_xaxis(xaxis_data=x)
    .add_yaxis(series_name='',y_axis=y,label_opts=opt.LabelOpts(is_show=False))
)
(
    Grid(init_opts=opt.InitOpts(width='620px',height='320px'))
    .add(points,grid_opts=opt.GridOpts(pos_bottom='60%'))
    .add(lines,grid_opts=opt.GridOpts(pos_top='60%'))
).render_notebook()

Python数据可视化——pyecharts可视化(一)_第7张图片

# 两个图画在同一个图表上
num = [110, 136, 108, 48, 111, 112, 103]
num2 = [90, 110, 101, 70, 90, 120, 99]
lab = ['哈士奇', '萨摩耶', '泰迪', '金毛', '牧羊犬', '吉娃娃', '柯基']
bar = (
    Bar(init_opts=opt.InitOpts(width='720px',height='320px'))
    .add_xaxis(xaxis_data=lab)
    .add_yaxis(series_name='',yaxis_data=num)
)
lines = (
    Line()
    .add_xaxis(xaxis_data=lab)
    .add_yaxis(series_name='',y_axis=num,label_opts=opt.LabelOpts(is_show=False))
)
bar.overlap(lines).render_notebook()

Python数据可视化——pyecharts可视化(一)_第8张图片

你可能感兴趣的:(python相关)