Subfiguren in matplotlib
Soms wil je meerdere subplots combineren in één figuur.
Dat kan door tegelijk een figuur en assen te maken met de functie plot.subplots().
Deze functie retourneert het figure- en axes-object:
import matplotlib.pyplot as plt
# Create a figure and axes
fig, (ax1, ax2) = plt.subplots(number_of_rows, number_of_columns)
Je kunt deze axes-objecten nu gebruiken om grafieken te maken:
# Use the axes to plot visualizations
ax1.hist(df['column_1'])
ax2.hist(df['column_2'])
plt.show()
Deze oefening maakt deel uit van de cursus
Python voor R-gebruikers
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
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()