Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Drawing Violin Plots | Section
Statistical Visualization with Seaborn
セクション 1.  12
single

single

bookDrawing Violin Plots

メニューを表示するにはスワイプしてください

A violinplot is a hybrid of a box plot and a kernel density plot (KDE).

While a boxplot only shows summary statistics (median, quartiles), a violinplot reveals the full distribution of the data. The "width" of the violin at any given point represents the density (how many data points are there).

Key Parameters

  • split=True: if you have a hue variable with exactly two categories (e.g., "Male"/"Female"), this parameter draws one category on the left half of the violin and the other on the right. This makes comparing them incredibly easy;
  • inner: controls what is drawn inside the violin;
  • 'box' (default): draws a mini boxplot;
  • 'point': draws individual data points;
  • 'quartile': draws lines for the 25th, 50th, and 75th percentiles;
  • bw (bandwidth): controls the smoothness of the curve (just like in KDE). A smaller number reveals more detail (and noise); a larger number makes it smoother.

Example

Here is a violinplot showing the total_bill distribution. Notice how split=True allows us to compare "Smokers" vs "Non-Smokers" inside the same violin.

123456789101112131415161718
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('tips') # Create a split violinplot sns.violinplot( data=df, x='day', y='total_bill', hue='smoker', split=True, # Compare sides directly inner='quartile', # Show quartile lines palette='muted' ) plt.show()
copy
タスク

スワイプしてコーディングを開始

Create a detailed visualization of the tips data.

  1. Import the necessary libraries and read the tips.csv dataset.
  2. Create a violinplot and assign the result to a variable named g (this captures the plot's Axes object):
    • Map 'day' to x and 'total_bill' to y.
    • Group by 'sex' using hue.
    • Use the 'rocket' palette.
    • Split the violins to compare genders side-by-side (split=True).
    • Show individual data points inside by setting inner='point'.
    • Set the smoothing bandwidth bw to 0.2.
  3. Set the title of the plot to 'Tips violinplot' using the g variable (e.g., g.set_title(...)).
  4. Display the plot.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  12
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt