Article Directory
Pyecharts
Basic Charting Example:
Pie:
brief introduction: Pie chart shows the percentage of a data series.
- Import library:
from pyecharts import options as opts
from pyecharts.charts import Pie
- InstantiationPie():
p=Pie()
- Setting data:
v1 = ['python','java','php','c','go']
v2 = [116,90,42,97,68]
v3 = [list(i) for i in zip(v1,v2)]
# data_pair 格式为 [(key1, value1), (key2, value2)]
p.add(series_name="编程语言",data_pair=v3)
- Set the color pie chart:
p.set.colors(["blue", "green", "purple", "red", "black"])
- Set the global configuration items:
p.set_global_opts(title_opts=Opts.TitleOpts(title="编程语言占比"))
- Set series configuration item (tag):
Brief description:b: Data name,c: Data values
p.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
- Display Legend:
p.render_notebook()
dash board:
- Import library:
import pyecharts.options as opts
from pyecharts.charts import Gauge
- Examples of == Gauge () == size and arranged:
g = Gauge(init_opts=opts.InitOpts(width="800px", height="500px"))
- adding data:
g.add(series_name="业务指标", data_pair=[["完成率", 55.5]])
- Set global configuration items (CIs legend, prompt box configuration items):
p.set_global_opts(
# 显示图例样件 False 不显示
legend_opts=opts.LegendOpts(is_show=False),
# is_show 是否显示提示框 formatter标签内容格式器,
tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"),
)
- Display Legend:
g.render_notebook()
Boxplot:
brief introduction: The main data comprising six nodes, a set of data in descending order, were calculated his upper edge, the upper quartile Q3, median, lower quartile Q1, a lower edge, there is a outliers.
- Guide library
from pyecharts import options as opts
from pyecharts.charts import Boxplot
- InstantiationBoxplot:
b = Boxplot()
- Add data into the xy axis:
# 每个箱线图的y轴数据都是以列表填充
v1 = [
[850, 740, 900, 1070, 930, 850, 950, 980, 980, 880]
,[1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960],
]
v2 = [
[890, 810, 810, 820, 800, 770, 760, 740, 750, 760]
, [910, 920, 890, 860, 880, 720, 840, 850, 850, 780],
]
# 添加两个x轴数据 列表形式
b.add_xaxis(["exp1","exp2"])
# 添加y轴的数据以及图例
b.add_yaxis("A", b.prepare_data(v1))
b.add_yaxis("B", b.prepare_data(v2))
- Set the global configuration items:
b.set_global_opts(title_opts=opts.TitleOpts(title="箱线图实例"))
- Display Legend:
b.render_notebook()
Multi-layered map:
Line graph and a bar graph superimposed
- Library guide:
from pyecharts import options as opts
from pyecharts.charts import Bar, Line
- InstantiationBar()withLine():
b = Bar()
l = Line()
- Adding xy axis data provided Series Name:
v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
v4 = ['{:2d}月'.format(s) for s in range(1,13)]
# 设置x轴的数据
b.add_xaxis(xaxis_data=v4)
# 增加y轴数据并且设置系列名
b.add_yaxis("蒸发量",v1)
b.add_yaxis("降水量",v2)
- Extended x / y-axis, where the y-axis expansion Q (refer toglobal_options.AxisOptsConfiguration is selected in the official document global species)Axis label CI:
b.extend_axis(yaxis=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} °C"), interval=5))
- Set Series configuration items:
# 是否显示标签 这里为False 不显示标签 可以改为True查看效果
b.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
- Set the global configuration items:
b.set_global_opts(
title_opts=opts.TitleOpts(title="Overlap-bar+line"),
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} ml")),
)
- Setting data line chart:
l.add_axis(v4)
#yaxis_index 使用的 y 轴的 index
l.add_yaxis(series_name="平均温度",y_axis=v3,yaxis_index=1)
- Both figures Fusion:
b.overlap(l)
- Display Legend:
b.render_notebook()
Upper and lower histogram overlay:
- Import library:
from pyecharts import options as opts
from pyecharts.charts import Bar
- InstantiationBar():
b = Bar()
- Adding x, y-axis data, and sets the stack:
v1=[1,2,3,4,5]
v2=[6,7,8,9,10]
v3=["{:2d}".format(x) for x in range(5)]
b.add_xaxis(v3)
b.add_yaxis("A",v1,stack="A")
b.add_yaxis("b",v2,stack="A")
- Set the global configuration items:
b.set_global_opts(title_opts=opts.TitleOpts(title="stack图"))
- Showing columns:
b.render_notebook()