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()
# 线图
(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()
# 饼图
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()
# 环图
(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()
# 玫瑰图
(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()
# 直方图
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()
# 并行多图
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()
# 两个图画在同一个图表上
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()