乐于分享
好东西不私藏

Excel 图表不够用?Python 这 5 张图让老板眼前一亮

Excel 图表不够用?Python 这 5 张图让老板眼前一亮

📊 还在用 Excel 默认配色?

辛辛苦苦做的报告,老板看一眼就说”不够专业”?

❌ 颜色太土,像 90 年代的 PPT
❌ 图表单调,看不出重点
❌ 同样的数据,为什么别人做的更好看

✨ 今天教你 5 张 Python 基础图,学会后老板看你的眼神都会变!


📁 一、先看效果对比

📌 1.1 折线图 – 销售趋势

2026 年销售趋势1 月2 月3 月4 月5 月6 月7 月

📌 1.2 柱状图 – 部门对比

各部门销售额对比华东华南华北华西线上线下100 万130 万160 万180 万200 万170 万

📌 1.3 饼图 – 产品占比

产品销售占比产品 A 40%产品 B 30%产品 C 20%产品 D 10%

📌 1.4 散点图 – 用户分布

用户年龄 vs 消费金额20 岁年龄60 岁

📌 1.5 面积图 – 累计趋势

累计销售额趋势Q1Q2Q3Q4

✨ 怎么样?是不是比 Excel 默认的好看多了?


💻 二、完整代码

import matplotlib.pyplot as plt
import seaborn as sns

# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False

# 数据
months = ['1 月', '2 月', '3 月', '4 月', '5 月', '6 月', '7 月']
sales = [120, 150, 180, 220, 260, 300, 340]

# 创建图表
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(months, sales, marker='o', linewidth=2, color='#667eea')
ax.fill_between(months, sales, alpha=0.3, color='#667eea')

# 美化
ax.set_title('2026 年销售趋势', fontsize=16, fontweight='bold')
ax.set_xlabel('月份', fontsize=12)
ax.set_ylabel('销售额 (万元)', fontsize=12)
ax.grid(True, alpha=0.3)

# 保存
plt.savefig('销售趋势图.png', dpi=300, bbox_inches='tight')

🔍 三、代码详解

📌 3.1 导入库

import matplotlib.pyplot as plt
import seaborn as sns

💡 说明:matplotlib 是基础绘图库,seaborn 基于 matplotlib,默认配色更好看。

📌 3.2 设置中文字体

plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False

⚠️ 重要提示:

不设置中文字体的话,中文会显示为方框!Windows 用 SimHei,Mac 用 Arial Unicode MS,Linux 用 WenQuanYi Micro Hei。

📌 3.3 准备数据

months = ['1 月', '2 月', '3 月', '4 月', '5 月', '6 月', '7 月']
sales = [120, 150, 180, 220, 260, 300, 340]

📌 3.4 绘制图表

fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(months, sales, marker='o', linewidth=2, color='#667eea')
ax.fill_between(months, sales, alpha=0.3, color='#667eea')

💡 参数说明:figsize 设置大小,marker=’o’ 用圆点标记,fill_between 填充线下区域。

🚀 四、进阶用法

📌 4.1 多线条对比

# 同时画今年和去年的数据
ax.plot(months, sales_2026, label='2026 年', color='#667eea')
ax.plot(months, sales_2025, label='2025 年', color='#999')
ax.legend()  # 显示图例

📌 4.2 组合图表

# 柱状图 + 折线图
ax.bar(months, revenue, color='#11998e', label='收入')
ax2 = ax.twinx()
ax2.plot(months, profit_rate, color='#fc4a1a', marker='o', label='利润率')

📌 4.3 导出高清图

# 公众号用
plt.savefig('chart.png', dpi=300, bbox_inches='tight')

# 打印用
plt.savefig('chart.pdf', dpi=600, bbox_inches='tight')

# 网页用(矢量图!)
plt.savefig('chart.svg', bbox_inches='tight')

⚠️ 五、注意事项

💡 字体问题:

  • Windows:
     plt.rcParams[‘font.sans-serif’] = [‘SimHei’]
  • Mac:
     plt.rcParams[‘font.sans-serif’] = [‘Arial Unicode MS’]
  • Linux:
     plt.rcParams[‘font.sans-serif’] = [‘WenQuanYi Micro Hei’]

💡 负号显示:

必须设置 plt.rcParams['axes.unicode_minus'] = False,否则负号会显示为方框!

💡 图片大小:

  • 公众号文章:
    600-800px 宽
  • PPT 演示:
    1920×1080
  • 打印报告:
    300 DPI 以上

💬 互动福利

你在用 Excel 画图时遇到过哪些坑?留言区告诉我,点赞最高的 3 位读者,送Python 可视化模板合集(含 10 种常用图表代码)!

📅 下期预告

04-22《销售趋势这样画,老板一眼看懂增长规律》

✅ 同比/环比怎么画?
✅ 双折线图对比技巧
✅ 趋势线自动拟合

📊 本文代码已上传

关注公众号,回复”可视化入门”获取完整代码 + 示例数据