ComenzarEmpieza gratis

Subfigures in matplotlib

Sometimes you want to combine several subplots in a single figure.

You can do this by creating a figure and an axes simultaneously by using the plot.subplots() function. This function returns the figure and the axes objects:

import matplotlib.pyplot as plt

# Create a figure and axes 
fig, (ax1, ax2) = plt.subplots(number_of_rows, number_of_columns)

You can now use these axes objects to generate plots:

# Use the axes to plot visualizations
ax1.hist(df['column_1'])
ax2.hist(df['column_2'])
plt.show()

Este ejercicio forma parte del curso

Python for R Users

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

import matplotlib.pyplot as plt

# Create a figure with 1 axes
fig, ax = plt.____(1, 1)

# Plot a scatter plot in the axes
____.scatter(tips____, tips____)
plt.show()
Editar y ejecutar código