
In this example, we introduce Seaborn, a statistical data visualization library built on top of Matplotlib. Seaborn provides a convenient way to create informative statistical plots with relatively little code.
We use a histogram with an overlaid kernel density estimate (KDE) to compare temperature distributions across different experimental groups.
First, we load the experimental measurements using Pandas.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("../data/measurements.csv")
Next, we use the histplot() function to visualize the temperature distribution.
sns.histplot(
data=df,
x="temperature",
hue="group",
kde=True,
stat="density",
common_norm=False,
bins=40,
alpha=0.4
)
The data parameter specifies the DataFrame, while x defines the variable displayed on the horizontal axis.
The hue="group" parameter separates measurements by experimental group using different colors.
The kde=True option adds a kernel density estimate curve, providing a smoothed representation of the temperature distribution.
The stat="density" parameter normalizes the histogram so that the total area represents a probability density rather than raw measurement counts.
The common_norm=False option normalizes each group independently, making it easier to compare their distribution shapes.
Finally, bins=40 specifies the number of histogram intervals, while alpha=0.4 controls transparency.
We add a title and adjust the layout before displaying the figure.
plt.title("Temperature Distribution by Group")
plt.tight_layout()
plt.show()

In addition to histograms, Seaborn provides other useful visualizations for comparing statistical distributions. In this example, we use boxplots and violin plots to compare temperature measurements across experimental groups.
First, we create a figure containing two plots arranged horizontally.
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
The plt.subplots() function creates a figure with one row and two columns. The resulting axes array allows us to display both visualizations side by side.
The first subplot displays temperature distributions using a boxplot.
sns.boxplot(
data=df,
x="group",
y="temperature",
hue="group",
legend=False,
ax=axes[0]
)
A boxplot summarizes the distribution using several statistical measures:
• The central line represents the median.
• The box represents the interquartile range (IQR), containing the middle 50% of observations.
• The whiskers show the spread of the data.
• Individual points outside the whiskers represent potential outliers.
The ax=axes[0] parameter places the plot in the first subplot.
The second subplot displays the same data using a violin plot.
sns.violinplot(
data=df,
x="group",
y="temperature",
hue="group",
legend=False,
inner="quart",
ax=axes[1]
)
Unlike boxplots, violin plots show the estimated probability density of the data using a kernel density estimate (KDE).
The width of each violin indicates where observations are more concentrated. Wider regions represent higher data density, while narrower regions indicate fewer observations.
The inner="quart" parameter displays quartile information inside each violin, making it easier to compare the distribution with a traditional boxplot.
Finally, we add titles to both subplots and display the figure.
axes[0].set_title("Temperature Boxplot")
axes[1].set_title("Temperature Violinplot")
plt.tight_layout()
plt.show()
The resulting visualization allows us to compare experimental groups from two statistical perspectives. Boxplots provide a compact summary of medians, quartiles, and potential outliers, while violin plots reveal additional information about the shape and density of each temperature distribution.

In addition to analyzing individual distributions, we can investigate relationships between several physical quantities simultaneously. Seaborn provides the pairplot() function, which creates a matrix of plots showing pairwise relationships between selected variables.
First, we define the physical quantities that we want to compare.
columns = [
"temperature",
"pressure",
"energy",
"velocity_x",
]
These variables represent different physical properties measured during the experiment. We also include the experimental group to distinguish measurements belonging to different groups.
Next, we use the pairplot() function to generate the visualization.
sns.pairplot(
df[columns + ["group"]],
hue="group",
diag_kind="kde",
corner=True,
plot_kws={"alpha": 0.4, "s": 12}
)
The df[columns + ["group" expression selects only the variables required for the analysis.
The hue="group" parameter assigns different colors to observations from different experimental groups, making comparisons easier.
The diag_kind="kde" option displays kernel density estimates on the diagonal, showing the distribution of each individual variable.
The corner=True parameter displays only the lower triangular part of the plot matrix, avoiding duplicated scatter plots.
Finally, we display the complete pair plot.
plt.show()
The resulting visualization allows us to examine correlations, identify potential relationships between physical quantities, detect clusters, and compare patterns across experimental groups.

In addition to examining pairwise relationships using scatter plots, we can summarize the relationships between multiple physical quantities using a correlation matrix. Seaborn provides the heatmap() function, which represents correlation coefficients using colors.
First, we define the physical quantities included in the analysis.
columns = [
"temperature",
"pressure",
"energy",
"velocity_x",
"velocity_y",
"velocity_z"
]
These variables represent temperature, pressure, energy, and the three velocity components.
Next, we calculate the correlation coefficients between all selected variables.
corr = df[columns].corr()
The corr() function calculates the Pearson correlation coefficient for each pair of variables by default.
Correlation values range from -1 to 1:
• Values close to 1 indicate a strong positive linear relationship.
• Values close to -1 indicate a strong negative linear relationship.
• Values close to 0 indicate a weak or absent linear relationship.
We use Seaborn's heatmap() function to visualize the correlation matrix.
plt.figure(figsize=(9, 7))
sns.heatmap(
corr,
annot=True,
cmap="coolwarm",
vmin=-1,
vmax=1,
center=0,
square=True,
linewidths=0.5
)
The annot=True parameter displays the numerical correlation coefficients inside each cell.
The cmap="coolwarm" parameter defines the color scheme, while vmin and vmax specify the minimum and maximum correlation values. The center=0 parameter ensures that zero correlation corresponds to the center of the color scale.
The square=True option makes all cells square, and linewidths controls the thickness of the lines separating them.
Finally, we add a title and display the visualization.
plt.title("Experimental Data Correlation")
plt.tight_layout()
plt.show()
The resulting heatmap provides a compact overview of correlations between experimental variables. It helps identify strongly related quantities, potential dependencies, and patterns that may require further investigation.