Lecture 5: Data Viz II
What can we do? Generically, nothing more than frequency. A table or a figure.
could you turn that into a lollipop chart
Could you constuct a mosaic plot of risk and fees?
The core idea is they exist on a continuum; the likelihood of any particular realization is usually zero.
As a result:
Show a histogram of assets
show a histogram of assets with bins of size 100 million starting with 0 to 100 million
A violin, boxplot, and raincloud
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Create the boxenplot for 'Return 2009' by 'Type'
plt.figure(figsize=(8, 5))
sns.boxenplot(x='Type', y='Return 2009', data=df, palette='muted')
# Styling
plt.title('Boxenplot of 2009 Returns by Fund Type')
plt.xlabel('Fund Type')
plt.ylabel('Return 2009 (%)')
plt.grid(axis='y', linestyle='--', alpha=0.3)
plt.tight_layout()Note
Prompt: Can you show a violin plot of returns in 2009 by risk and type?
# Set categorical order for Risk
risk_order = ['Below average', 'Average', 'Above average']
df['Risk'] = pd.Categorical(df['Risk'], categories=risk_order, ordered=True)
# Create the violin plot
plt.figure(figsize=(8, 5))
sns.violinplot(x='Risk', y='Return 2009', hue='Type', data=df, split=True, palette='muted', inner='quartile')
# Styling
plt.title('Violin Plot of 2009 Returns by Risk and Fund Type', fontsize=14)
plt.xlabel('Risk Level', fontsize=12)
plt.ylabel('Return 2009 (%)', fontsize=12)
plt.legend(title='Fund Type')
plt.grid(axis='y', linestyle='--', alpha=0.3)
plt.tight_layout()Note
Prompt: That is quite nice. I would prefer that they be oriented horizontally with each rising above the horizontal axis
Important
Prompt: create a scatterplot of returns by assets
Prompt: create a scatterplot of expense ratios and returns with symbols from fees and colors from risk
Important
Prompt: use a checkmark for yes and an X for no as the symbols

BUS 1301 [29 Jan 26]