Subplots
Uppgift
Swipe to start coding
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.
Lösning
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 8
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal