python工具——cutecharts
cutecharts手绘风格图形库
github 地址https://github.com/cutecharts/cutecharts.py
安装
pip install cutecharts
使用
eg:
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方法会在脚本当前目录生成一个 render.html 文件
cutecharts.faker为cutecharts内置的测试数据
用浏览器打开render.html
柱状图
from cutecharts.charts import Bar from cutecharts.components import Page from cutecharts.faker import Faker def bar(): 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 bar().render()
饼图
from cutecharts.charts import Pie from cutecharts.components import Page from cutecharts.faker import Faker def pie_radius(): chart = Pie("Pie-Radius") chart.set_options( labels=Faker.choose(), inner_radius=0, ) chart.add_series(Faker.values()) return chart pie_radius().render()
雷达图
from cutecharts.charts import Radar def radar_base() -> Radar: chart = Radar("Radar-基本示例") data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada', 'Nevada'], 'pop1': [1.5, 1.7, 3.6, 2.4, 2.9, 3.2], 'pop2': [2.5, 1.2, 2.4, 1.5, 2.2, 2.9]} chart.set_options(labels=data.get('state')) chart.add_series("series-A", data.get('pop1')) chart.add_series("series-B", data.get('pop2')) return chart radar_base().render()