又一款超酷的 Python 可视化神器:cutecharts
Python学习与数据挖掘
共 7965字,需浏览 16分钟
· 2022-01-03
关注"Python学习与数据挖掘",
设为“置顶或星标”,第一时间送达干货
前言
安装
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()
修改图例位置
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()
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()
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()
修改内圈半径
# 虚假数据
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()
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()
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()
点连线
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()
组合图表——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()
原文链接:https://blog.csdn.net/qq_27484665/article/details/115472329
长按或扫描下方二维码,后台回复:加群,即可申请入群。一定要备注:来源+研究方向+学校/公司,否则不拉入群中,见谅!
(长按三秒,进入后台)
推荐阅读
评论
了解加密货币到加密货币的互换
1、什么是加密货币互换?加密货币到加密货币的互换是指以现行市场汇率将一种加密货币直接兑换为另一种加密货币。与需要法定货币存款和较长流程的传统交易所不同,加密货币到加密货币的互换可以无缝地促进交换。掉期在提高加密货币的流动性和效率方面发挥着重要作用。该功能使用户能够将他们的加密货币与钱包中的其他代币进
区块链头条
0
李彦宏:开源大模型不如闭源,后者会持续领先;周鸿祎:“开源不如闭源” 的言论是胡说八道
架构师大咖
架构师大咖,打造有价值的架构师交流平台。分享架构师干货、教程、课程、资讯。架构师大咖,每日推送。
公众号该公众号已被封禁0、李彦宏:开源大模型不如闭源,后者会持续领先当今
源码共读
0
【第129期】程序员的新宠:三款终端工具,让你告别Xshell!
概述 WindTerm:跨平台的SSH利器 首先介绍的是WindTerm,这是一款使用C语言开发的跨平台SSH客户端。它不仅完全免费,而且没有商业使用的限制。WindTerm支持SSH v2、Telnet、Raw Tcp等协议,而且性能出色,甚至超过了FinalShell和Electerm。功能
前端微服务
0
字节员工:35岁以后被裁员的,后来都走了哪条路?现在2-2,要不要利用最后一年拼命上个岸。
架构师大咖
架构师大咖,打造有价值的架构师交流平台。分享架构师干货、教程、课程、资讯。架构师大咖,每日推送。
公众号该公众号已被封禁在当今竞争激烈的职场环境中,年龄并不总是一个决定性
源码共读
0
上班的时候,有一群摸鱼搭子非常重要...
上班的时候,有一群摸鱼搭子非常重要!一到上班时间,他们就从四面八方涌进群里冒泡...从八卦聊到股市、从职场聊到乌X兰局势,偶尔还会复读、相亲、battle...然后,下午6点钟准时消失不见...所以你要不要加入我们一起摸鱼?我们有北京、上海、深圳、广州、杭州、武汉、成都、南京等8个城市的摸鱼群,还有
产品经理日记
0
周四002 瑞超:同样落寞的境遇——北雪平vs埃尔夫斯堡
上赛季最终排名联赛第9的北雪平本赛季伊始表现不佳,4轮战罢他们仅以1胜1平2负的战绩排在倒数第三,这支历史上曾夺得13次联赛冠军、6次杯赛冠军老牌劲旅,正如英格兰赛场上的一众百年俱乐部,在低谷中不断探索着出路。球队主教练安德烈亚斯·阿尔姆曾是AIK索尔纳及赫根队的主教练,他于今年年初刚刚拿起球队教鞭
产品与体验
0
雷军辟谣了!不是高考状元,卡里也没有冰冷的 40 亿
架构师大咖
架构师大咖,打造有价值的架构师交流平台。分享架构师干货、教程、课程、资讯。架构师大咖,每日推送。
公众号该公众号已被封禁最近很火的雷军简历,听说落魄时卡里只有冰冷的 40
源码共读
0
日本影山优佳最新杂志照,展现充满透明感的美丽
今天的图文分享的是影山优佳的杂志写真。元日向坂46的影山优佳,登上了写真杂志《周刊FLASH》5/7和5/14合并号的封面。影山优佳是日本艺人、女演员、前偶像。身高155厘米。2001年5月8日出生于东京都。2023年7月从组合日向坂46毕业,之后作为演员活跃的影山优佳,在《周刊FLAS
python教程
0