又一款超酷的 Python 可视化神器:cutecharts

前言

今天给大家介绍一个很酷的 Python 手绘风格可视化神包:cutecharts

和 Matplotlib 、pyecharts 等常见的图表不同,使用这个包可以生成看起来像手绘的各种图表,在一些特殊场景下使用效果可能会更好。

GitHub 地址:

https://github.com/chenjiandongx/cutecharts

它的画风是这样的:
d50fcc365dd0fa02d16fba90ae2f733e.png

  • cutecharts是由pyecharts作者chenjiandongx开源的一个轻量级的项目;

  • 目前支持BarLinePieRadarScatter五种图表;

  • 支持Page组合图表;

安装
  •  pip install cutecharts;

Line——基本示例

支持的参数直接参考源码中的注释就好~

def set_options(
        self,
        labels: Iterable,
        x_label: str = "",
        y_label: str = "",
        y_tick_count: int = 3,
        legend_pos: str = "upLeft",
        colors: Optional[Iterable] = None,
        font_family: Optional[str] = None,
    ):
        """
        :param labels: X 坐标轴标签数据
        :param x_label: X 坐标轴名称
        :param y_label: Y 坐标轴名称
        :param y_tick_count: Y 轴刻度分割段数
        :param legend_pos: 图例位置,有 "upLeft", "upRight", "downLeft", "downRight" 可选
        :param colors: label 颜色数组
        :param font_family: CSS font-family
        """




def add_series(self, name: str, data: Iterable):
        """
        :param name: series 名称
        :param data: series 数据列表
        """
基本示例
from cutecharts.charts import Line
# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data_1 = [57, 134, 137, 129, 145, 60, 49]
y_data_2 = [114, 55, 27, 101, 125, 27, 105]


chart = Line("Mobile phone sales")
chart.set_options(
    labels=x_data, 
    x_label="Brand", 
    y_label="Sales",
)
chart.add_series("series-A", y_data_1)
chart.add_series("series-B", y_data_2)
chart.render_notebook()

af2d49d13e32ce8e7011f6a58970a7a9.png

修改图例位置

from cutecharts.charts import Line
# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data_1 = [57, 134, 137, 129, 145, 60, 49]
y_data_2 = [114, 55, 27, 101, 125, 27, 105]


chart = Line("Mobile phone sales")
chart.set_options(
    labels=x_data, 
    x_label="Brand", 
    y_label="Sales",
    legend_pos="upRight"
)
chart.add_series("series-A", y_data_1)
chart.add_series("series-B", y_data_2)
chart.render_notebook()

40e37c68c1f93d548d745e667ffd9a44.png

Bar——基本示例

不支持多个系列的数据~

def set_options(
        self,
        labels: Iterable,
        x_label: str = "",
        y_label: str = "",
        y_tick_count: int = 3,
        colors: Optional[Iterable] = None,
        font_family: Optional[str] = None,
    ):
        """
        :param labels: X 坐标轴标签数据
        :param x_label: X 坐标轴名称
        :param y_label: Y 坐标轴名称
        :param y_tick_count: Y 轴刻度分割段数
        :param colors: label 颜色数组
        :param font_family: CSS font-family
        """


def add_series(self, name: str, data: Iterable):
        """
        :param name: series 名称
        :param data: series 数据列表
        """
基本示例
# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data = [57, 134, 137, 129, 145, 60, 49]


chart = Bar("Mobile phone sales")
chart.set_options(
    labels=x_data, 
    x_label="Brand", 
    y_label="Sales",
    colors=Faker.colors
)
chart.add_series("series-A", y_data)


chart.render_notebook()

8b6e26ff4ce840c82dd5dbff61c7b0bd.png

Pie——基本示例

def set_options(
        self,
        labels: Iterable,
        inner_radius: float = 0.5,
        legend_pos: str = "upLeft",
        colors: Optional[Iterable] = None,
        font_family: Optional[str] = None,
    ):
        """
        :param labels: 数据标签列表
        :param inner_radius: Pie 图半径
        :param legend_pos: 图例位置,有 "upLeft", "upRight", "downLeft", "downRight" 可选
        :param colors: label 颜色数组
        :param font_family: CSS font-family
        """




def add_series(self, data: Iterable):
        """
        :param data: series 数据列表
        """
基本示例
# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data = [57, 134, 137, 129, 145, 60, 49]


chart = Pie("Mobile phone sales")
chart.set_options(
    labels=x_data, 
    colors=Faker.colors
)
chart.add_series(y_data)


chart.render_notebook()

43be890f5f9bbec540d5fb0597404806.png

修改内圈半径
# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data = [57, 134, 137, 129, 145, 60, 49]


chart = Pie("Mobile phone sales")
chart.set_options(
    labels=x_data, 
    inner_radius=0,
    colors=Faker.colors
)
chart.add_series(y_data)


chart.render_notebook()

c57c420e3836ec8fc5d5675822db7c27.png

Radar——基本示例

参考代码注释:

def set_options(
        self,
        labels: Iterable,
        is_show_label: bool = True,
        is_show_legend: bool = True,
        tick_count: int = 3,
        legend_pos: str = "upLeft",
        colors: Optional[Iterable] = None,
        font_family: Optional[str] = None,
    ):
        """
        :param labels: 数据标签列表
        :param is_show_label: 是否显示标签
        :param is_show_legend: 是否显示图例
        :param tick_count: 坐标系分割刻度
        :param legend_pos: 图例位置,有 "upLeft", "upRight", "downLeft", "downRight" 可选
        :param colors: label 颜色数组
        :param font_family: CSS font-family
        """




def add_series(self, name: str, data: Iterable):
        """
        :param name: series 名称
        :param data: series 数据列表
        """
基本示例
# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data_1 = [57, 134, 137, 129, 145, 60, 49]
y_data_2 = [114, 55, 27, 101, 125, 27, 105]


chart = Radar("Mobile phone sales")
chart.set_options(
    labels=x_data, 
    is_show_legend=True,
    colors=Faker.colors
)
chart.add_series("series-A", y_data_1)
chart.add_series("series-B", y_data_2)
chart.render_notebook()

ec54544908f82575fdced4fbae309d40.png

Scatter——基本示例

def set_options(
        self,
        x_label: str = "",
        y_label: str = "",
        x_tick_count: int = 3,
        y_tick_count: int = 3,
        is_show_line: bool = False,
        dot_size: int = 1,
        time_format: Optional[str] = None,
        legend_pos: str = "upLeft",
        colors: Optional[Iterable] = None,
        font_family: Optional[str] = None,
    ):
        """
        :param x_label: X 坐标轴名称
        :param y_label: Y 坐标轴名称
        :param x_tick_count: X 轴刻度分割段数
        :param y_tick_count: Y 轴刻度分割段数
        :param is_show_line: 是否将散点连成线
        :param dot_size: 散点大小
        :param time_format: 日期格式
        :param legend_pos: 图例位置,有 "upLeft", "upRight", "downLeft", "downRight" 可选
        :param colors: label 颜色数组
        :param font_family: CSS font-family
        """




def add_series(self, name: str, data: Iterable):
        """
        :param name: series 名称
        :param data: series 数据列表,[(x1, y1), (x2, y2)]
        """
基本示例
# 随机生成数据
data_1 = [(random.randint(0, 100), random.randint(0, 100)) for _ in range(100)]
data_2 = [(random.randint(0, 100), random.randint(0, 100)) for _ in range(100)]


chart = Scatter("random dot")
chart.set_options(
    x_label = "I'm x-label",
    y_label = "I'm x-yabel",
    x_tick_count = 3,
    y_tick_count = 3,
    is_show_line = False,
    dot_size = 1,
    legend_pos = "upLeft",
    colors=Faker.colors
)
chart.add_series("series-A", data_1)
chart.add_series("series-A", data_2)
chart.render_notebook()

fb2621c47579a8566da02c07b3dd2d08.png

点连线
# 随机生成数据
data_1 = [(random.randint(0, 100), random.randint(0, 100)) for _ in range(10)]
data_2 = [(random.randint(0, 100), random.randint(0, 100)) for _ in range(10)]


chart = Scatter("random dot")
chart.set_options(
    x_label = "I'm x-label",
    y_label = "I'm x-yabel",
    x_tick_count = 3,
    y_tick_count = 3,
    is_show_line = True,
    dot_size = 1,
    legend_pos = "upLeft",
    colors=Faker.colors
)
chart.add_series("series-A", data_1)
chart.add_series("series-A", data_2)
chart.render_notebook()

9857d4b855f633129e859b39d9759c98.png

组合图表——Page

# 虚假数据
x_data = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu', 'OnePlus']
y_data = [57, 134, 137, 129, 145, 60, 49]


chart_1 = Pie("Mobile phone sales")
chart_1.set_options(
    labels=x_data, 
    inner_radius=0.6,
    colors=Faker.colors
)
chart_1.add_series(y_data)




chart_2 = Bar("Mobile phone sales")
chart_2.set_options(
    labels=x_data, 
    x_label="Brand", 
    y_label="Sales",
    colors=Faker.colors
)
chart_2.add_series("series-A", y_data)


page = Page()
page.add(chart_1, chart_2)
page.render_notebook()

f0a179757d7546c6e92027f8c8d87a1b.png

原文链接:https://blog.csdn.net/qq_27484665/article/details/115472329

33493599c8f8a04bd0d2b2f0a60ceed1.gif

各位伙伴们好,詹帅本帅搭建了一个个人博客和小程序,汇集各种干货和资源,也方便大家阅读,感兴趣的小伙伴请移步小程序体验一下哦!(欢迎提建议)

推荐阅读

牛逼!Python常用数据类型的基本操作(长文系列第①篇)

牛逼!Python的判断、循环和各种表达式(长文系列第②篇)

牛逼!Python函数和文件操作(长文系列第③篇)

牛逼!Python错误、异常和模块(长文系列第④篇)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值