使用pyecharts的超市销售数据可视化项目代码。
时间: 2024-12-25 14:06:35 浏览: 23
PyEcharts是一个用于Python的数据可视化库,它可以方便地创建各种图表,如折线图、柱状图等。下面是一个简单的例子,展示如何使用PyEcharts对超市销售数据进行可视化:
```python
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Bar
# 假设我们有一个包含日期和销售额的DataFrame
data = {
'日期': ['01月', '02月', '03月', '04月', '05月', '06月'],
'商品A': [1000, 1500, 2000, 2500, 3000, 3500],
'商品B': [800, 900, 1000, 1100, 1200, 1300]
}
df = pd.DataFrame(data)
# 创建Bar chart
sales_chart = Bar(
"超市销售数据",
title_top="销售额", # 图表标题
width=1200,
height=600
)
# 添加数据到图表
for item in df.columns:
sales_chart.add_xaxis(df['日期'])
sales_chart.add_yaxis(item, df[item])
# 设置图形样式
sales_chart.set_global_opts(
xaxis_opts=opts.AxisOpts(axislabel_opts={'rotate': -45}),
tooltip_opts=opts.TooltipOpts(trigger='axis'),
legend_opts=opts.LegendOpts(is_show=False)
)
# 渲染图表
sales_chart.render('超市销售数据.html')
```
在这个例子中,我们首先读取数据,然后创建一个Bar图表,并将日期作为x轴,商品名称作为y轴的系列添加进去。最后,通过设置全局选项调整了标题、坐标轴标签旋转和提示框样式。
阅读全文
相关推荐


















