Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Subplots | Data Visualization
Gaining Insights with Data Visualization

book
Subplots

Tarea
test

Swipe to show code editor

Let's continue with a more advanced graph. Plot 4 histograms side by side:

  • Plot the first histogram based on the 'sepal_length' column.
  • Plot the second histogram based on the 'sepal_width' column.
  • Plot the third histogram based on the 'petal_length' column.
  • Plot the fourth histogram based on the 'petal_width' column.

Solución

import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style='darkgrid')
df = sns.load_dataset('iris')

fig, axs = plt.subplots(2, 2, figsize=(7, 7))

# Plot 4 histograms
sns.histplot(data=df, x='sepal_length', color='skyblue', ax=axs[0, 0])
sns.histplot(data=df, x='sepal_width', color='olive', ax=axs[0, 1])
sns.histplot(data=df, x='petal_length', color='gold', ax=axs[1, 0])
sns.histplot(data=df, x='petal_width', color='teal', ax=axs[1, 1])

plt.show()

Mark tasks as Completed
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 8
some-alt