Unlike common charts such as Matplotlib and pyecharts, cutecharts package can generate various charts that look like hand-drawn charts

cutecharts github

  • cutecharts is a lightweight project open sourced by pyecharts author chenjiandongx .

  • Currently supports five types of charts: Bar, Line, Pie, Radar and Scatter.

  • Support for Page combination charts;

Installation

  •  pip install cutecharts;

Line Basic example1

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
        :param x_label
        :param y_label
        :param y_tick_count
        :param legend_pos
        :param colors
        :param font_family: CSS font-family
        """


def add_series(self, name: str, data: Iterable):
        """
        :param name: series
        :param data: series
        """

Line Basic example2

from cutecharts.charts import Line
# False data
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()

 

 

cutecharts

Modify legend location

from cutecharts.charts import Line
# False data
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()

 

cutecharts

Bar Basic Examples

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
        :param x_label
        :param y_label
        :param y_tick_count
        :param colors: label
        :param font_family
        """

def add_series(self, name: str, data: Iterable):
        """
        :param name: series
        :param data: series
        """

 

Bar Basic Example 2

# False data
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()

 

cutecharts

Pie Basic Example

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 label
        :param inner_radius
        :param legend_pos
        :param colors: label
        :param font_family: CSS font-family
        """


def add_series(self, data: Iterable):
        """
        :param data: series
        """

 

Pie Basic Example 2

# False data
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()

 

cutecharts

Modify inner circle radius

# False data
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()

 

cutecharts

Radar basic example

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
        :param colors: label
        :param font_family: CSS font-family
        """


def add_series(self, name: str, data: Iterable):
        """
        :param name: series
        :param data: series
        """

 

Rada Basic Example 2

# False data
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()

 

cutecharts

Scatter Basic Examples

   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
        :param y_label
        :param x_tick_count
        :param y_tick_count
        :param is_show_line
        :param dot_size
        :param time_format
        :param legend_pos
        :param colors: label
        :param font_family: CSS font-family
        """


def add_series(self, name: str, data: Iterable):
        """
        :param name: series
        :param data: series
        """

 

Scatter Basic Examples2

# Randomly generated data
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()

 

cutecharts

dotted line

# Randomly generated data
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()

 

cutecharts

Combination Charts

# False data
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()

Related articles

How to make a dynamic QR code using Python?

Code Note: If the background image we use is a dynamic gif, the generated code is a dynamic QR code. If the background image is a static image, the generated code is a static QR code.

8 best VS Code extensions for Python

1. Python extension for Visual Studio Code 2.Python Preview 3.Sort lines 4.Git Graph 5.Python Snippets 6.Better Comments 7.autoDocstring 8.Python Indent

3 Tips for Simplifying Function Calls in Python

For example, these solutions in this article are generally not used in daily life and work, so you do not need to memorize them, but you need to know that there are such problems and there are these solutions

Minecraft in python

You should have heard of Minecraft, but have you ever thought of writing a game like this yourself? This article tells you to use python to write a Minecraft

shodan python tutorial

Crawl the IP addresses of all devices on the Internet and their port numbers using Shodan python sdk