Error in user YAML: (<unknown>): could not find expected ':' while scanning a simple key at line 3 column 1
---
- oeasy Python 0824
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
本教程同步发布在:
个人网站: `https://oeasy.org`
蓝桥云课: `https://www.lanqiao.cn/courses/3584`
GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
Gitee: `https://gitee.com/overmind1980/oeasypython`
---这是一段示例实验介绍。
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# 设置中文字体
plt.rcParams['font.sans-serif'] = ['WenQuanYi Zen Hei'] # 文泉驿正黑
plt.rcParams['axes.unicode_minus'] = False
# 示例数据保持不变
channels = ['搜索引擎', '社交媒体', '电子邮件', '直接访问', '推荐链接']
products = ['产品A', '产品B', '产品C', '产品D']
# 创建贡献数据矩阵
contribution_data = np.array([
[150, 80, 120, 90], # 搜索引擎
[100, 120, 80, 70], # 社交媒体
[60, 50, 90, 100], # 电子邮件
[80, 70, 60, 50], # 直接访问
[40, 60, 50, 80] # 推荐链接
])
# 创建热力图
plt.figure(figsize=(10, 8))
sns.heatmap(contribution_data,
annot=True,
fmt='d',
cmap='YlOrRd',
xticklabels=products,
yticklabels=channels,
annot_kws={'size': 12}) # 调整数字大小
plt.title('营销渠道对产品销售的贡献矩阵', fontsize=14, pad=20) # 调整标题大小和位置
plt.xlabel('产品', fontsize=12)
plt.ylabel('营销渠道', fontsize=12)
# 调整标签位置和大小
plt.xticks(rotation=0) # 横向显示x轴标签
plt.tick_params(labelsize=10) # 调整刻度标签大小
plt.tight_layout() # 自动调整布局
plt.show()
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。
