本人以官方文档,部分书籍为学习资源,记录个人笔记,仅作为学习交流使用。 创作不易,未经作者允许,禁止转载,更勿做其他用途。
原文链接:https://blog.csdn.net/t4ngw/article/details/110423036
1.饼图
from pyecharts import options as opts
from pyecharts.charts import Pie
c = (
Pie()
.add("", [['a', 10],
['b', 10],
['c', 10],
['d', 10],
['e', 10],
['f',10],
['g', 10]])
.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"])
.set_global_opts(title_opts=opts.TitleOpts(title="Pie"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
.render("pie.html")
)
饼图结果:
2.柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
c = (
Bar()
.add_xaxis(['语文', '数学', '外语'])
.add_yaxis("2017", [67.61, 71.89, 52.34])
.add_yaxis("2019", [70.25, 80.69, 64.34], category_gap="60%")
.set_global_opts(
title_opts=opts.TitleOpts(title="2017和2019年各科平均成绩对比"),
yaxis_opts=opts.AxisOpts(
name='分数',
name_location='middle',
name_gap=30,
name_textstyle_opts=opts.TextStyleOpts(
font_family= 'Times New Roman',
font_size=16,
color='black',
font_weight='bolder',
)),xaxis_opts=opts.AxisOpts(
name='科目',
name_location='middle',
name_gap=30,
name_textstyle_opts=opts.TextStyleOpts(
font_family= 'Times New Roman',
font_size=16,
color='black',
font_weight='bolder',
)),
).render("bar.html")
)
柱状图结果:
3.折线图
import pyecharts.options as opts
from pyecharts.charts import Line
c2 = (
Line()
.add_xaxis(["2016", "2017", "2018", "2019", "2020"])
.add_yaxis("经费", [1345, 1415, 1462.5, 1565.3, 1695.9], label_opts=opts.LabelOpts(is_show=False, position="center"))
.set_global_opts(title_opts=opts.TitleOpts(title="2016—2020年中央财政对城乡义务教育补助经费(亿元)", pos_left="center",
pos_top="20", ),
legend_opts=opts.LegendOpts(is_show=False),
yaxis_opts=opts.AxisOpts(
name='经费(亿元)',
name_location='middle',
name_gap=30,
name_textstyle_opts=opts.TextStyleOpts(
font_family= 'Times New Roman',
font_size=16,
color='black',
font_weight='bolder',
)),xaxis_opts=opts.AxisOpts(
name='年份',
name_location='middle',
name_gap=30,
name_textstyle_opts=opts.TextStyleOpts(
font_family= 'Times New Roman',
font_size=16,
color='black',
font_weight='bolder',
)),).render("Line.html")
)
折线图结果:
4.环形图
from pyecharts import options as opts
from pyecharts.charts import Pie
c = (
Pie()
.add("", [['a', 10],
['b', 10],
['c', 10],
['d', 10],
['e', 10],
['f',10],
['g', 10]],
radius=["40%", "50%"])
.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"])
.set_global_opts(title_opts=opts.TitleOpts(title="Pie"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
.render("ring.html")
)
环形图结果
博客对您有所帮助的话,欢迎给个赞啦,你的鼓励是对我最大的支持! 有不足之处也请您评论指教!