6.1 — eine Linie pro Frucht:
fig, ax = plt.subplots(figsize=(8, 6))
ax.plot(fruits.columns, fruits.loc['Apple'], color='green', label='Apple')
ax.plot(fruits.columns, fruits.loc['Banana'], color='blue', label='Banana')
ax.plot(fruits.columns, fruits.loc['Cherry'], color='red', label='Cherry')
ax.legend()
plt.show()
6.2 — drei Balken pro Wochentag, versetzt um width:
import numpy as np
xticks = np.arange(len(fruits.columns))
w = 0.3
ax.bar(xticks - w, fruits.loc['Apple'], width=w, color='green')
ax.bar(xticks, fruits.loc['Banana'], width=w, color='blue')
ax.bar(xticks + w, fruits.loc['Cherry'], width=w, color='red')
ax.set_xticks(xticks)
ax.set_xticklabels(fruits.columns)
6.3 — drei Subplots, gestapelt, geteilte Achsen:
fig, (apple_ax, banana_ax, cherry_ax) = plt.subplots(
nrows=3, ncols=1, figsize=(8, 6), sharex=True, sharey=True
)
apple_ax.bar(fruits.columns, fruits.loc['Apple'], color='green')
banana_ax.bar(fruits.columns, fruits.loc['Banana'], color='blue')
cherry_ax.bar(fruits.columns, fruits.loc['Cherry'], color='red')