matplotlib运用:电商广告投入及销量预测【数据集+完整代码】

前期准备

数据准备

数据集有两个表

  1. 销售数据表
  2. 投放费用的广告费用表

文章源码获取方式 👉👉 点击文末名片

1. 分别按 日 和 月 分析销售收入

绘制子图

figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None,frameon=True)
	num:图像编号或名称.数字为编号,字符串为名称
    figsize:指定figure的宽和高.单位为英寸
    dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 1英寸等于2.5cm,A4纸是21*30cm的纸张
	facecolor:背景颜色
	edgecolor:边框颜色
	frameon:是否显示边框

(1 ) subplot语法
subplot(nrows,ncols,sharex,sharey,subplot_kw.**fig_kw)

nrows       subplot的行数
ncols       subplot的列数
sharex      所有subplot应该使用相同的X轴刻度.(调节xlim将会影响所有subplot)
sharey      所有subplot应该使用相同的Y轴刻度(调节ylim将会影响所有subplot)
subplot_kw  用于创建各subplot的关键字字典
**fig_kw    创建figure时的其他关键字,如plt.subplots(2,2,figsize=(8,6))
import pandas as pd
import matplotlib.pyplot as plt

pd.set_option('display.unicode.east_asian_width', True) 


df = pd.read_excel('.\data\销售表.xlsx')  
df = df[['日期', '销售码洋']]  
df['日期'] = pd.to_datetime(df['日期'])  
df1 = df.set_index('日期')  
df_d = df1.resample('D').sum().to_period('D')  
df_d.to_excel(r'.\result\result1.xlsx')  

df_m = df1.resample('M').sum().to_period('M')  
df_m.to_excel(r'.\result\result2.xlsx')  

plt.rc('font', family='SimHei', size=10) 

fig = plt.figure(figsize=(9, 5)) 
ax = fig.subplots(1, 2) 

ax[0].set_title('按日分析销售收入')  # 设置图表标题
df_d.plot(kind
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值