CuteCharts: A Lightweight Python Visualization Library – Installation and Basic Examples
This article introduces the lightweight Python visualization library cutecharts, explains its installation, and provides step‑by‑step code examples for creating line, bar, pie, radar, scatter charts and combined page charts, demonstrating how to customize options such as labels, legends, colors, and inner radius.
The article presents cutecharts , a lightweight Python visualization library created by the author of pyecharts . It highlights the library’s support for five basic chart types—Bar, Line, Pie, Radar, and Scatter—as well as composite Page charts.
Installation
Install the package via pip:
<code>pip install cutecharts</code>Line Chart – Basic Example
<code>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 数据列表
"""
</code> <code># 虚假数据
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()
</code>Modifying Legend Position
<code># 虚假数据
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()
</code>Bar Chart – Basic Example
<code># 虚假数据
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()
</code>Pie Chart – Basic Example
<code># 虚假数据
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()
</code>Modifying Inner Radius
<code># 虚假数据
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()
</code>Radar Chart – Basic Example
<code># 虚假数据
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()
</code>Scatter Chart – Basic Example
<code># 随机生成数据
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()
</code>Scatter Chart – Points Connected by Lines
<code># 随机生成数据
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()
</code>Composite Page Chart
<code># 虚假数据
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()
</code>The article concludes with visual outputs for each chart type, demonstrating the ease of generating and customizing charts using cutecharts in a Jupyter notebook environment.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.