今天我们介绍的可视化工具是 cutecharts[1],这是一个纯 Python 语言编写的可视化工具,就像其名字一样,这是一个可以产生 cute 版图表的工具。
柱状图
基本柱状图
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()
Output:
调整颜色
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
Output:
折线图
基本折线图
from cutecharts.charts import Line from cutecharts.components import Page from cutecharts.faker import Faker def line_base() -> Line: chart = Line("Line-基本示例") chart.set_options(labels=Faker.choose(), x_label="I'm xlabel", y_label="I'm ylabel") chart.add_series("series-A", Faker.values()) chart.add_series("series-B", Faker.values()) return chart line_base().render()
Output:
Legend 位置
def line_legend(): chart = Line("Line-Legend 位置") chart.set_options(labels=Faker.choose(), legend_pos="upRight") chart.add_series("series-A", Faker.values()) chart.add_series("series-B", Faker.values()) return chart
Output:
调整颜色
def line_tickcount_colors(): chart = Line("Line-调整颜色") chart.set_options(labels=Faker.choose(), colors=Faker.colors, y_tick_count=8) chart.add_series("series-A", Faker.values()) chart.add_series("series-B", Faker.values()) return chart
Output:
饼图
基本饼图
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()
Output:
Legend 位置
def pie_legend_font(): chart = Pie("Pie-Legend") chart.set_options( labels=Faker.choose(), legend_pos="downLeft", font_family='"Times New Roman",Georgia,Serif;', ) chart.add_series(Faker.values()) return chart
Output:
Radius 调整
def pie_radius(): chart = Pie("Pie-Radius") chart.set_options( labels=Faker.choose(), inner_radius=0, ) chart.add_series(Faker.values()) return chart
Output:
雷达图
基本雷达图
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()
Output:
颜色调整
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
Output:
散点图
基本散点图
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()
Output:
散点大小
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
Output:
散点连成线
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
Output:
好了,这就是今天分享的全部内容,喜欢就点个赞吧~
参考资料
[1]
cutecharts: https://github.com/cutecharts/cutecharts.py