Hand Made Visualizations in Python using Cutecharts
Last Updated on May 9, 2024 by Editorial Team
Author(s): Kashish Rastogi
Originally published on Towards AI.
Want to add a sprinkle of sweetness to your infographics?
Okay, this blog will not be like old blogs where I will be listing out how to make charts using Python libraries.
As a data enthusiast and practitioner, I was no stranger to the world of charts and graphs. Yet, despite my best efforts, my visualizations lacked that certain punch and sweetness. I will never forget a time when I would surf endlessly through the internet just to find a way to make the charts more interesting.
Letβs just say i got a box full of sweetness in the form of Cutecharts!
Enter Cutecharts! into the menu of the Python library. Itβs like the cupcake of data visualization β adding the personal touch that makes charts less intimidating and more inviting.
Unlike the typical Matplotlib and Seaborn libraries, we have somehting fun and enjoyfull charting libary.
Cutecharts brings handmade charm to the table, with adorable charts that are as delightful as they are informative. Plus, itβs got a hovering effect (just like Plotly), giving you control over your data.
From sweet Bar and Pie charts to spunky Radar, Scatter, and Line charts, Cutecharts has got your back. Itβs like having a chart-making BFF whoβs always there to make your data look fabulous!
Before we start to draw cute charts, we need to install the cutechart library using pip.
$ pip install cutecharts
Let us use the traditional dataset (Netflix) for exploring cutechart library.
# Importing library
import cutecharts.charts as ctc
# Importing data
import pandas as pd
Reading the Netflix dataset
df_netf = pd.read_csv('../input/netflix-shows/netflix_titles.csv')
df_netf[:2]
letβs whip up some data magic with Cutecharts!
Charts
First, we will make the basic chart β Pie.
Donβt picture a desert Pie, we will make a Pie Chart that is as delightful as grandmaβs apple pie! With Cutecharts, you can slice and dice your data into mouthwatering segments or even eat the whole pie.
To make a pie chart we will collect the latest 5 years of movie count. First, we will collect the data of latest release year count using the value_counts()
function.
df_year = df_netf['release_year'].value_counts().reset_index().sort_values(by='index', ascending=False)[:5].rename(columns={'index':'release_year','release_year':'Count'})
Pie chart
pie_chart = ctc.Pie('Last 5 years movies count', width='600px', height='300px')
# set the chart option
pie_chart.set_options(labels=list(df_year['release_year']), inner_radius=0)
# label to be shown on graph while hovering the chart (eg: count number 1147)
pie_chart.add_series(list(df_year['Count']))
# display the chart
pie_chart.render_notebook()
Parameters of the chart
width
: Specify the width of the chartheight
: Specify the height of the chartlabels
: Specify the labels of the chart, which we want to put in the chartinner_radius
: Specify the inner radius of the chart, 0 means there will be no space in the middle of the chart
To make a piechart, we will first use the ctc.Pie()
and use other parameters as per the need of the chart. Now, setting the chart options using the variable_name.set_options()
such as labels for the x-axis and y-axis.
Donut chart
Who says data visualization canβt be sweet? Meet the Donut Chart, we will make using the Python Library.
It is a delightful twist on the classic Pie Chart.
With Cutecharts, you can serve up your data in a tasty ring of information. Itβs like having your data and eating it too! So letβs go ahead, letβs indulge in some data donuts and satisfy the night and day craving for data insights.
# Donut chart
donut_chart = ctc.Pie('Last 5 years movies count', width='600px', height='300px')
# set the chart options
donut_chart.set_options(labels=list(df_year['release_year']), inner_radius=0.7)
# label to be shown on graph
donut_chart.add_series(list(df_year['Count']))
# display the charts
donut_chart.render_notebook()
Parameter of the chart
width
: Specify the width of the chartheight
: Specify the height of the chartlabels
: Specify the labels of the chart, which we want to put in the chartinner_radius
: Specify the inner radius of the chart, 0.7 means there will be space in the 70% area
To make a donut chart we will first use the ctc.Pie()
and use other parameters as per the need of the chart. Now, setting the chart options using the variable_name.set_options()
such as labels for the x-axis and y-axis.
Bar chart
I can feel the heat of raising the heat of sweetness with the Cutechartsβ Bar Chart!
Whether youβre plotting sales figures or ranking your favorite ice cream flavors, this chart is your go-to chart. It serves up visual refreshments with style usign the Cutechartsβ Bar Chart. With colorful bars that pop like confetti, data has never looked so festive.
Cheers to making charts as fun as happy hour!
rating = pd.DataFrame(df_netf['rating'].value_counts()).reset_index()[:7].rename(columns={'index':'rating','rating':'count'})
# bar chart
bar = ctc.Bar("Distribution of Rating")
# set the chart options
bar.set_options(labels=list(rating.rating),
x_label='Rating',
y_label='Count')
# label to be shown on graph
bar.add_series('Count',list(rating['count']))
# display the chart
bar.render_notebook()
Parameters of the chart
width
: Specify the width of the chartheight
: Specify the height of the chartlabels
: Setting the value for the labels in the chartx_label
: Setting the value for the x labels in the charty_label
: Setting the value for the y labels in the chart
To make a bar chart we will first use the ctc.Bar()
and use other parameters as per the need of the chart. Now, setting the chart options using the variable_name.set_options()
such as labels for the x-axis and y-axis.
Line chart
Letβs take a bareke from the sweetness and use something which is more informative to use in the chart.
Get ready to connect the dots and chart your course to success with Cutechartsβ Line Chart! Like a trusty GPS for your data journey, this chart helps you navigate trends and patterns with ease. Whether youβre tracking stock prices or plotting your rollercoaster emotions throughout the day, this Line Chart keeps you on the straight and narrow path to data enlightenment.
To make a line chart we will collect the first 15 years of movieβs impact.
data = df_netf.groupby('release_year').count()['show_id'].reset_index().head(15)
chart = ctc.Line("Impact of First 15 Movie over the years of 19's", width='700px', height='500px')
# set the chart options
chart.set_options(labels=list(data['release_year']),
x_label='Years',
y_label='Count',
)
# label to be shown on graph
chart.add_series('Years',list(data['show_id']))
# display the chart
chart.render_notebook()
Parameters of the chart
width
: Specify the width of the chartheight
: Specify the height of the chartlabels
: Setting the value for the labels in the chartx_label
: Setting the value for the x labels in the charty_label
: Setting the value for the y labels in the chart
To make a line chart we will first use the ctc.Line()
and use other parameters as per the need of the chart. Now, setting the chart options using the variable_name.set_options()
such as labels for the x-axis and y-axis. To set the values in the x-axis use variable_name.add_series()
where add the values in the form of a list.
Conclusion
In the world of data visualization, where charts and graphs show all the information, adding a touch of sweetness can make all the difference. With Cutecharts, weβve unlocked a treasure trove of delightful charts that not only inform but also enchant.
Gone are the days of boring bar charts and uninspired line graphs. Thanks to Cutecharts, we can now infuse our data with personality and flair, creating visualizations that are as charming as they are informative.
So, the next time you find yourself lost in a sea of bland charts, remember this: Cutecharts is your secret weapon for turning data into something truly delightful. Cheers to making charts as fun as a happy hour!
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.
Published via Towards AI