場景 效果 cutecharts的Github: https://github.com/chenjiandongx/cutecharts 註: 博客: https://blog.csdn.net/badao_liumang_qizhi 關註公眾號 霸道的程式猿 獲取編程相關電子書、教程推送與免費下載 ...
場景
效果
cutecharts的Github:
https://github.com/chenjiandongx/cutecharts
註:
博客:
https://blog.csdn.net/badao_liumang_qizhi
關註公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載。
實現
安裝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()
效果