Today, I’m going to introduce you to a cool Python freehand style visualization package: Cutecharts.

Unlike more common diagrams like Matplotlib and Pyecharts, you can use this package to generate various diagrams that look like hand-drawn diagrams, which might work better in some scenarios.

Making address:

Github.com/chenjiandon…

To draw these diagrams, it’s easy to install the library with a single command:

pip install cutecharts
Copy the code

You can also install it using source code:

$ git clone https://github.com/chenjiandongx/cutecharts.git
$ cd cutecharts
$ pip install -r requirements.txt
$ python setup.py install
Copy the code

Here’s how each chart is drawn.

First, there are some parameters common to charts:

Commons

Different charts have some of the same approach.

__init__

Params                                          Desc
------                                          ----
title: Optional[str] = NoneChart title width:str = "800px"Chart width height:str = "600px"Chart height assets_host:Optional[str] = NoneReference resource HostCopy the code

render

Params                                          Desc
------                                          ----
dest: str = "render.html"Render file path template_name:str = "basic_local.html"The template used for rendering generally does not need to be modifiedCopy the code

render_notebook

Params                                          Desc
------                                          ----
template_type: str = "basic"The type of template used for rendering does not generally need to be modifiedCopy the code

load_javascript

Load JS dependencies to be used during JupyterLab rendering.Copy the code

Bar (Bar chart)

cutecharts.charts.Bar
Copy the code

API

cutecharts.charts.Bar.set_options

Params Desc ------ ---- labels: Iterable X coordinate label data x_label:str = ""X axis name y_label:str = ""Y axis name y_tick_count:int = 3Number of Y-axis scale segmentation segments colors:Optional[Iterable] = NoneLabel color array font_family:Optional[str] = None               CSS font-family
Copy the code

cutecharts.charts.Bar.add_series

Params                                          Desc
------                                          ----
name: strSeries Name Data: Iterable Series data listCopy the code

Demo

Bar- Basic example

from cutecharts.charts import Bar
from cutecharts.components import Page
from cutecharts.faker import Faker


def bar_base() -> Bar:
    chart = Bar("Bar- Basic Example")
    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()
Copy the code

If you want the source code, you can “click” it

Bar- Adjust color

def bar_tickcount_colors() :
    chart = Bar("Bar- Adjust color")
    chart.set_options(labels=Faker.choose(), y_tick_count=10, colors=Faker.colors)
    chart.add_series("series-A", Faker.values())
    return chart
Copy the code

Line graph

cutecharts.charts.Line
Copy the code

API

cutecharts.charts.Line.set_options

Params Desc ------ ---- labels: Iterable X coordinate label data x_label:str = ""X axis name y_label:str = ""Y axis name y_tick_count:int = 3Number of Y scale segments legend_pos:str = "upLeft"Legend location, yes"upLeft"."upRight"."downLeft"."downRight"Optional colors:Optional[Iterable] = NoneLabel color array font_family:Optional[str] = None               CSS font-family
Copy the code

cutecharts.charts.Line.add_series

Params                                          Desc
------                                          ----
name: strSeries Name Data: Iterable Series data listCopy the code

Demo

Line- Basic example

from cutecharts.charts import Line
from cutecharts.components import Page
from cutecharts.faker import Faker


def line_base() -> Line:
    chart = Line("Line- Basic Example")
    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()
Copy the code

The Line – Legend location

def line_legend() :
    chart = Line("The Line - Legend position")
    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
Copy the code

Line- Adjusts the color

def line_tickcount_colors() :
    chart = Line("Line- Adjust color")
    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
Copy the code

Pie chart

cutecharts.charts.Pie
Copy the code

API

cutecharts.charts.Pie.set_options

Params Desc ------ ---- labels: Iterable list of data labels inner_radius:float = 0.5Pie diagram radius legend_pos:str = "upLeft"Legend location, yes"upLeft"."upRight"."downLeft"."downRight"Optional colors:Optional[Iterable] = NoneLabel color array font_family:Optional[str] = None               CSS font-family
Copy the code

cutecharts.charts.Pie.add_series

Params Desc ------ ---- data: Iterable series data listCopy the code

Demo

Pie- Basic example

from cutecharts.charts import Pie
from cutecharts.components import Page
from cutecharts.faker import Faker


def pie_base() -> Pie:
    chart = Pie("Pie- Basic Example")
    chart.set_options(labels=Faker.choose())
    chart.add_series(Faker.values())
    return chart


pie_base().render()
Copy the code

Pie-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

Copy the code

Pie-Radius

def pie_radius() :
    chart = Pie("Pie-Radius")
    chart.set_options(
        labels=Faker.choose(),
        inner_radius=0,
    )
    chart.add_series(Faker.values())
    return chart
Copy the code

Radar

cutecharts.charts.Radar
Copy the code

API

cutecharts.charts.Radar.set_options

Params Desc ------ ---- labels: Iterable list of data labels is_show_label:bool = TrueWhether to display the tag is_show_LEGEND:bool = TrueDisplay legend tick_count:int = 3Coordinate system split scale legend_pos:str = "upLeft"Legend location, yes"upLeft"."upRight"."downLeft"."downRight"Optional colors:Optional[Iterable] = NoneLabel color array font_family:Optional[str] = None               CSS font-family
Copy the code

cutecharts.charts.Radar.add_series

Params                                          Desc
------                                          ----
name: strSeries Name Data: Iterable Series data listCopy the code

Demo

Radar- Basic example

from cutecharts.charts import Radar
from cutecharts.components import Page
from cutecharts.faker import Faker


def radar_base() -> Radar:
    chart = Radar("Radar- Basic Example")
    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()
Copy the code

Radar- Color adjustment

def radar_legend_colors() :
    chart = Radar("Radar- Color Adjustment")
    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
Copy the code

Scatter

cutecharts.charts.Scatter
Copy the code

API

cutecharts.charts.Scatter.set_options

Params                                          Desc
------                                          ----
x_label: str = ""X axis name y_label:str = ""Y axis name x_tick_count:int = 3Number of X axis scale segments y_tick_count:int = 3Y axis scale segmentation segment is_show_line:bool = FalseDot_size:int = 1Time_format:Optional[str] = NoneDate format legend_pos:str = "upLeft"Legend location, yes"upLeft"."upRight"."downLeft"."downRight"Optional colors:Optional[Iterable] = NoneLabel color array font_family:Optional[str] = None               CSS font-family
Copy the code

cutecharts.charts.Scatter.add_series

Params                                          Desc
------                                          ----
name: strData: Iterable series data list, [(x1, y1), (x2, y2)]Copy the code

Demo

Scatter- Basic examples

from cutecharts.charts import Scatter
from cutecharts.components import Page
from cutecharts.faker import Faker


def scatter_base() -> Scatter:
    chart = Scatter("Scatter- Basic Examples")
    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()
Copy the code

Scatter- Scatter size

def scatter_dotsize_tickcount() :
    chart = Scatter("Scatter- Scatter size")
    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
Copy the code

Scatter- The scattered points are connected into lines

def scatter_show_line() :
    chart = Scatter("Scatter- Line up")
    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
Copy the code

I spent three days to compile a set of Python learning tutorials, from the most basic Python scripts to Web development, crawlers, data analysis, data visualization, machine learning, etc. These materials can be “clicked” by the friends who want them