Color with care

Sequential vs rainbow.

Sequential vs rainbow.

Goal

Run every block and look at the Plot panel.

data = np.array([[48, 55, 92, 150], [22, 18, 40, 80], [60, 70, 110, 140]])
plt.imshow(data, cmap="Blues")
plt.xticks(range(4), ["Jan", "Feb", "Mar", "Apr"])
plt.yticks(range(3), ["Nairobi", "Mombasa", "Kisumu"])
plt.colorbar(label="mm")
plt.title("Sequential rainfall")
plt.show()
data = np.array([[48, 55, 92, 150], [22, 18, 40, 80], [60, 70, 110, 140]])
plt.imshow(data, cmap="rainbow")
plt.title("Rainbow hides order")
plt.colorbar()
plt.show()
df = pd.DataFrame({
    "city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
    "units": [21, 15, 15, 18, 12],
    "shillings": [2100, 1500, 1480, 1750, 1190],
})
plt.bar(df["city"], df["units"], color=["#1d4f7a" if c == "Nairobi" else "#9aa5b1" for c in df["city"]])
plt.title("Highlight one city")
plt.show()
print("One highlight color beats five competing hues.")
Pitfall

Always plt.show(). Paste the whole editor.