DataFrame-level Visualization Examples#
Basic examples of visualization methods.
Used Libraries#
The following methods selectively use these libraries:
import plotly.io as pio
pio.renderers.default = "notebook"
Bar Chart#
bar() - Basic bar chart showing average values by category.
from frameon import load_dataset, FrameOn as fo
titanic = fo(load_dataset('titanic'))
fig = titanic.viz.bar(
x='class',
y='fare',
color='sex',
facet_col='embarked',
agg_func='mean',
text_auto='.0f',
title='Average Fare by Class, Sex and Embarkation Port',
width=900
)
fig.show()
Line Chart#
line() - Time series line chart showing trends over time.
from frameon import load_dataset, FrameOn as fo
superstore = fo(load_dataset('superstore'))
fig = superstore.viz.line(
x='Order Date',
y='Sales',
color='Category',
agg_func='mean',
freq='ME',
title='Average Sales Over Time by Category'
)
fig.show()
Area Chart#
area() - Stacked area chart showing composition over time.
from frameon import load_dataset, FrameOn as fo
superstore = fo(load_dataset('superstore'))
fig = superstore.viz.area(
x='Order Date',
y='Sales',
color='Category',
agg_func='mean',
freq='ME',
title='Sales Composition Over Time by Category'
)
fig.show()
Box Plot#
box() - Shows distribution of values across categories.
from frameon import load_dataset, FrameOn as fo
superstore = fo(load_dataset('superstore'))
fig = superstore.viz.box(
x='Category',
y='Sales',
color='Segment',
show_dual=True,
upper_quantile=0.95,
show_legend_title=True,
title='Sales Distribution by Category and Segmen (Right: to 0.95 Quantile)'
)
fig.show()
Heatmap#
heatmap() - Heatmap showing relationships between two categorical variables.
from frameon import load_dataset, FrameOn as fo
titanic = fo(load_dataset('titanic'))
fig = titanic.viz.heatmap(
x='class',
y='alive',
z='age',
agg_func='mean',
do_pivot=True,
text_auto='.2f',
title='Average Age by Passenger Class and Survival Status',
width=600,
height=400
)
fig.show()
Pairplot#
pairplot() - Matrix of scatterplots showing relationships between numeric variables.
from frameon import load_dataset, FrameOn as fo
iris = fo(load_dataset('iris'))
fig = iris.viz.pairplot(
pairs=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'],
color_mode='category',
color_column='species',
renderer=None,
width=900
)
fig.show()
Colored by kernel density estimation.
from frameon import load_dataset, FrameOn as fo
iris = fo(load_dataset('iris'))
fig = iris.viz.pairplot(
pairs=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'],
color_mode='kde',
renderer=None,
width=900
)
fig.show()
Pie/Bar Combo Chart#
pie_bar() - Creates pie/bar combo charts
from frameon import load_dataset, FrameOn as fo
diamonds = fo(load_dataset('diamonds'))
fig = diamonds.viz.pie_bar(
y='cut',
x='price',
agg_func='mean',
text_auto='.0f',
pull=0.1,
category_orders={'cut': 'descending'},
title='Average Diamond Price by Cut Quality'
)
fig.show()
Histogram#
histogram() - Shows distribution of a numeric variable.
Base mode display simple histogram.
from frameon import load_dataset, FrameOn as fo
titanic = fo(load_dataset('titanic'))
fig = titanic.viz.histogram(
x='age',
color='alive',
title='Passenger Age Distribution by Survival Status'
)
fig.show()
Displays a dual plot with the original histogram on the left and a trimmed histogram (based on quantiles) on the right.
from frameon import load_dataset, FrameOn as fo
superstore = fo(load_dataset('superstore'))
fig = superstore.viz.histogram(
x='Sales',
color='Category',
mode='dual_hist_trim',
upper_quantile=0.95,
nbins=20,
title='Sales Distribution by Category (Right: to 0.95 Quantile)'
)
fig.show()
Displays a dual plot with a boxplot on the left and a trimmed histogram (based on quantiles) on the right.
from frameon import load_dataset, FrameOn as fo
superstore = fo(load_dataset('superstore'))
fig = superstore.viz.histogram(
x='Sales',
color='Region',
show_hist=False,
show_kde=True,
mode='dual_box_trim',
upper_quantile=0.95,
nbins=20,
show_legend_title=True,
title='Sales Distribution by Region (Right: to 0.95 Quantile)'
)
fig.show()
Categorical Comparison#
cat_compare() - Compares categorical distributions
from frameon import load_dataset, FrameOn as fo
titanic = fo(load_dataset('titanic'))
titanic.viz.cat_compare(
cat1='class',
cat2='embarked',
text_auto=True
)
Word Cloud#
wordcloud() - Visualizes word frequencies from text data.
Click and drag to zoom into specific areas.
from frameon import load_dataset, FrameOn as fo
reviews = fo(load_dataset('reviews'))
reviews.viz.wordcloud(
text_column='Text',
)
Parallel Categories#
parallel_categories() - Shows relationships between multiple categorical variables.
from frameon import load_dataset, FrameOn as fo
titanic = fo(load_dataset('titanic'))
fig = titanic.viz.parallel_categories(
dimensions=['class', 'sex', 'alive'],
title='Titanic Passenger Characteristics Flow',
width=900
)
fig.show()
Period Change#
period_change() - Shows changes between time periods.
from frameon import load_dataset, FrameOn as fo
superstore = fo(load_dataset('superstore'))
fig = superstore.viz.period_change(
date_col='Order Date',
metric_col='Sales',
agg_func='sum',
period='mom',
title='Month-over-Month Sales Change'
)
fig.show()