Create Stunning Charts with Cufflinks in Minutes – A Python Visualization Guide
This article introduces the Python cufflinks library, showing how its simple DataFrame‑based API and built‑in themes let you create a variety of attractive charts—bar, line, scatter, bubble, subplots, box, histogram, and 3D—using just a few lines of code.
Previously I used matplotlib and pyecharts, but recently discovered cufflinks, a Python visualization library that combines simplicity with beautiful charts.
1. Simple Usage
The cufflinks library works with pandas DataFrames; the main plotting function is DataFrame.iplot. It accepts many parameters such as:
kind: chart type (scatter, pie, histogram, etc.)
mode: lines, markers, lines+markers
colors: trace colors
dash: line style (solid, dash, dashdot)
width: line width
xTitle: x‑axis label
yTitle: y‑axis label
title: chart titleExample of a bar chart:
import pandas as pd
import numpy as np
import cufflinks as cf
df = pd.DataFrame(np.random.rand(12, 4), columns=['a','b','c','d'])
df.iplot(kind='bar', title='Example', xTitle='X axis', yTitle='Y axis')2. Beautiful Charts with Minimal Code
Cufflinks provides several themes (polar, pearl, henanigans, solar, ggplot, space, white) that style the charts.
Line Chart
cf.datagen.lines(4,10).iplot(mode='lines+markers', theme='solar')Generating random data:
cf.datagen.lines(2,10) # 2 groups, 10 points eachScatter Chart
df = pd.DataFrame(np.random.rand(50,4), columns=['a','b','c','d'])
df.iplot(kind='scatter', mode='markers',
colors=['orange','teal','blue','yellow'],
size=20, theme='solar')Bubble Chart
df.iplot(kind='bubble', x='a', y='b', size='c', theme='solar')Subplots
df = cf.datagen.lines(4)
df.iplot(subplots=True, shape=(4,1), shared_xaxes=True,
vertical_spacing=.02, fill=True, theme='ggplot')Box Plot
cf.datagen.box(20).iplot(kind='box', legend=False, theme='ggplot')Histogram
df.iloc[:,0:3].iplot(kind='histogram')3D Chart
cf.datagen.scatter3d(5,4).iplot(kind='scatter3d',
x='x', y='y', z='z',
text='text', categories='categories')Hope this introduction sparks your interest; cufflinks offers many more features to explore.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
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.
