平滑曲线图是使用线形图的绘图数据,绘图前先根据数据进行三次样条插值,然后用插值后得到的更密集的点绘制线形图。平滑曲线图的线条更加平滑。
\[\]
根据给定数据绘图,编写pyECharts代码如下所示:
code.python
import pandas as pd
from pyecharts.charts import Line
from pyecharts import options as opts
df=pd.read_excel('07 销售收入0.xlsx',engine='openpyxl',index_col=0)
categories = df.index.tolist() # 索引列作为横轴
# 1. 创建平滑曲线图
line = Line()
line.add_xaxis(categories)
# 2. 动态添加所有数据系列
for col in df.columns[0:]: # 从第1列开始
line.add_yaxis(col, df[col].tolist(),is_smooth=True)
# 3. 配置图表
line.set_global_opts(
title_opts=opts.TitleOpts(title="平滑曲线图"),
toolbox_opts=opts.ToolboxOpts())
line.render("line_smooth.html")
运行代码,生成下图。
\[\]