Python中使用cutecharts实现简单的手绘风格的图表
程序员文章站
2024-01-20 16:34:46
场景 效果 cutecharts的Github: https://github.com/chenjiandongx/cutecharts 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书、教程推送与免费下载 ......
场景
效果
cutecharts的github:
注:
博客:
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
安装cutecharts
pip install cutecharts
简单折线图
新建cutecharts.py
from cutecharts.charts import line chart = line("某商场销售情况") chart.set_options( labels=["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"], x_label="i'm xlabel", y_label="i'm ylabel", ) chart.add_series("series-a", [57, 134, 137, 129, 145, 60, 49]) chart.add_series("series-b", [114, 55, 27, 101, 125, 27, 105]) chart.render()
运行后会在同目录下生成render.html
效果如上。
柱状图
新建py文件
from cutecharts.charts import bar from cutecharts.components import page from cutecharts.faker import faker def bar_base() -> bar: chart = bar("bar-基本示例") chart.set_options(labels=faker.choose(), x_label="i'm xlabel", y_label="i'm ylabel") chart.add_series("series-a", faker.values()) return chart bar_base().render() def bar_tickcount_colors(): chart = bar("bar-调整颜色") chart.set_options(labels=faker.choose(), y_tick_count=10, colors=faker.colors) chart.add_series("series-a", faker.values()) return chart page = page() page.add(bar_base(), bar_tickcount_colors()) page.render()
效果
饼状图
新建py文件
from cutecharts.charts import pie from cutecharts.components import page from cutecharts.faker import faker def pie_base() -> pie: chart = pie("pie-基本示例") chart.set_options(labels=faker.choose()) chart.add_series(faker.values()) return chart pie_base().render() def pie_legend_font(): chart = pie("pie-legend") chart.set_options( labels=faker.choose(), legend_pos="upright", font_family='"times new roman",georgia,serif;', ) chart.add_series(faker.values()) return chart def pie_radius(): chart = pie("pie-radius") chart.set_options(labels=faker.choose(), inner_radius=0) chart.add_series(faker.values()) return chart page = page() page.add(pie_base(), pie_legend_font(), pie_radius()) page.render()
效果
雷达图
新建py文件
from cutecharts.charts import radar from cutecharts.components import page from cutecharts.faker import faker def radar_base() -> radar: chart = radar("radar-基本示例") chart.set_options(labels=faker.choose()) chart.add_series("series-a", faker.values()) chart.add_series("series-b", faker.values()) return chart radar_base().render() def radar_legend_colors(): chart = radar("radar-颜色调整") chart.set_options(labels=faker.choose(), colors=faker.colors, legend_pos="upright") chart.add_series("series-a", faker.values()) chart.add_series("series-b", faker.values()) return chart page = page() page.add(radar_base(), radar_legend_colors()) page.render()
效果
散点图
新建py文件
from cutecharts.charts import scatter from cutecharts.components import page from cutecharts.faker import faker def scatter_base() -> scatter: chart = scatter("scatter-基本示例") chart.set_options(x_label="i'm xlabel", y_label="i'm ylabel") chart.add_series( "series-a", [(z[0], z[1]) for z in zip(faker.values(), faker.values())] ) chart.add_series( "series-b", [(z[0], z[1]) for z in zip(faker.values(), faker.values())] ) return chart scatter_base().render() def scatter_dotsize_tickcount(): chart = scatter("scatter-散点大小") chart.set_options(dot_size=2, y_tick_count=8) chart.add_series( "series-a", [(z[0], z[1]) for z in zip(faker.values(), faker.values())] ) chart.add_series( "series-b", [(z[0], z[1]) for z in zip(faker.values(), faker.values())] ) return chart def scatter_show_line(): chart = scatter("scatter-散点连成线") chart.set_options(y_tick_count=8, is_show_line=true) chart.add_series( "series-a", [(z[0], z[1]) for z in zip(faker.values(), faker.values())] ) chart.add_series( "series-b", [(z[0], z[1]) for z in zip(faker.values(), faker.values())] ) return chart page = page() page.add(scatter_base(), scatter_dotsize_tickcount(), scatter_show_line()) page.render()
效果
上一篇: pythony--运算符
下一篇: 荐 远程访问及控制实验