准备与你人分享的图表

Matplotlib 数据可视化入门

Ariel Rokem

Data Scientist

更改图表样式

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"])
ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"])
ax.set_xlabel("Time (months)")
ax.set_ylabel("Average temperature (Fahrenheit degrees)")
plt.show()

Matplotlib 数据可视化入门

选择样式

plt.style.use("ggplot")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Matplotlib 数据可视化入门

回到默认值

plt.style.use("default")
Matplotlib 数据可视化入门

可用样式

Matplotlib 数据可视化入门

"bmh" 样式

plt.style.use("bmh")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Matplotlib 数据可视化入门

Seaborn 样式

plt.style.use("seaborn-colorblind")

fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"]) ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show()

Matplotlib 数据可视化入门

选择绘图样式的指南

  • 深色背景通常可读性较差
  • 若颜色很重要,请考虑色盲友好选项
    • "seaborn-colorblind" 或 "tableau-colorblind10"
  • 若他人可能打印图表,请减少用墨
  • 若将以黑白打印,请用 "grayscale" 样式
Matplotlib 数据可视化入门

练习为你选择合适的样式!

Matplotlib 数据可视化入门

Preparing Video For Download...