Přidej souhrnné statistiky do grafu časové řady
Grafy časových řad a číselné souhrny lze vizualizovat v jednom grafu – stačí použít pandas API pro matplotlib spolu s metodou table:
# Plot the time series data in the DataFrame
ax = df.plot()
# Compute summary statistics of the df DataFrame
df_summary = df.describe()
# Add summary table information to the plot
ax.table(cellText=df_summary.values,
colWidths=[0.3]*len(df.columns),
rowLabels=df_summary.index,
colLabels=df_summary.columns,
loc='top')
Toto cvičení je součástí kurzu
Vizualizace dat časových řad v Pythonu
Pokyny k cvičení
Prohlédni si meat_mean v shellu – jde o DataFrame obsahující průměr všech časových řad z meat.
- Přiřaď všechny hodnoty z
meat_meanargumentucellText. - Přiřaď všechny hodnoty indexu
meat_meanargumenturowLabels. - Přiřaď názvy sloupců
meat_meanargumentucolLabels.
Interaktivní cvičení na vyzkoušení si v praxi
Vyzkoušejte si toto cvičení dokončením tohoto ukázkového kódu.
# Plot the meat data
ax = meat.plot(fontsize=6, linewidth=1)
# Add x-axis labels
ax.set_xlabel('Date', fontsize=6)
# Add summary table information to the plot
ax.table(cellText=meat_mean.____,
colWidths = [0.15]*len(meat_mean.columns),
rowLabels=meat_mean.____,
colLabels=meat_mean.____,
loc='top')
# Specify the fontsize and location of your legend
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 0.95), ncol=3, fontsize=6)
# Show plot
plt.show()