import pyecharts
pyecharts.__version__ #版本检查
import pyecharts.charts as pyec
x=['甲','乙','丙']
y=[300,800,600]
bar=pyec.Bar()
bar.add_xaxis(x)
bar.add_yaxis(series_name='A',yaxis_data=y)
bar.render_notebook()
y1=[344,677,690]
bar.add_yaxis(series_name='B',yaxis_data=y1)
bar.render_notebook()
import pyecharts.options as opts
bar.set_global_opts(title_opts=opts.TitleOpts(title='比较图'))
bar.render_notebook()
x1=['2017','2018','2019']
y1=[300,400,600]
line=pyec.Line()
line.add_xaxis(x1)
line.add_yaxis(series_name='A',y_axis=y1)
line.render_notebook()
y2=[1300,500,900]
line.add_yaxis(series_name='B',y_axis=y2)
line.render_notebook()
line.set_global_opts(
title_opts=opts.TitleOpts(title='第一幅图'),
tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='cross'))
line.render_notebook()
line.set_global_opts(
title_opts=opts.TitleOpts(title='第一幅图'),
tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='cross'),#
toolbox_opts=opts.ToolboxOpts(is_show=True,orient='horizontal')) #工具箱设置 orient=vertical让工具箱水平放置
line.render_notebook()
设置图表大小
x1=['2017','2018','2019']
y1=[300,400,600]
line1=pyec.Line(init_opts=opts.InitOpts(width='500px',height='300px'))
line1.add_xaxis(x1)
line1.add_yaxis(series_name='C',y_axis=y1)
line1.render_notebook()
#构造pie的数据
x_data=['a','b','c','d']
y_data=[345,764,654]
#pie设置指定格式
data_pair=list(zip(x_data,y_data))
print(data_pair)
[(‘a’, 345), (‘b’, 764), (‘c’, 654)]
pie=pyec.Pie()
pie.add(series_name='dfdf',data_pair=data_pair)
pie.render_notebook()
pie1=pyec.Pie()
pie1.add(series_name='dfdf',data_pair=data_pair,radius=['40%','75%'])
pie1.render_notebook()
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0,10,30)
y1=np.sin(x)
y2=np.cos(x)
plt.scatter(x,y1)
scatter=pyec.Scatter()
scatter.add_xaxis(xaxis_data=x)
scatter.add_yaxis(series_name='y=sin(x)',y_axis=y1,)
scatter.render_notebook()
scatter=pyec.Scatter()
scatter.add_xaxis(xaxis_data=x)
scatter.add_yaxis(series_name='y=sin(x)',y_axis=y1,
label_opts=opts.LabelOpts(is_show=False))#设置数据是否展示
scatter.render_notebook()
scatter.add_yaxis(
series_name='y=cos(x)',
y_axis=y2,
label_opts=opts.LabelOpts(is_show=False))
scatter.render_notebook()
scatter=pyec.Scatter()
scatter.add_xaxis(xaxis_data=x)
scatter.add_yaxis(series_name='y=sin(x)',y_axis=y1,
label_opts=opts.LabelOpts(is_show=False),#设置数据是否展示
symbol_size=30,#控制散点图点的大小
symbol='roundRect',#散点形状
)
scatter.render_notebook()