Lesson theory
Code in a =PY() cell can return a picture. Excel shows it as an object in the cell; from the Python menu
you can move it onto the sheet, above the grid, and resize it.
import matplotlib.pyplot as plt
df = xl("A1:B13", headers=True)
plt.bar(df["Month"], df["Sales"])
plt.title("Sales by Month")
plt.ylabel("Sales, $K")
Seaborn is built on top of Matplotlib and groups the data for you:
import seaborn as sns
df = xl("A1:C200", headers=True)
sns.barplot(data=df, x="City", y="Amount", estimator="sum") # bars = sum by city
sns.histplot(df["Amount"], bins=10) # distribution of order sizes
sns.boxplot(data=df, x="City", y="Amount") # spread and outliers
plt.bardraws columns,plt.plota line, andplt.scattera scatter plot;- in
sns.barplot, the defaultestimatoris the mean, not the sum. A common mistake is a chart labeled "Revenue" that actually shows the average order; - a histogram and a box plot show what ordinary Excel charts don't without extra setup: the distribution and outliers;
- a chart from Python is a static picture. It recalculates with the cell when the data changes, but you can't click its points or restyle it with the mouse the way you can with an Excel chart.
Test yourself
Enter — commit · F2 — edit · F4 — $ in a reference · Ctrl+C/Ctrl+V — copy and paste · Ctrl+Z — undo
Esc or F6 — leave the sheet for the «Check» button · Shift+Tab in the first cell — back to the page