# import sys
# sys.path.append("../")
import pandas as pd
from pyecharts.faker import Faker
from pandasecharts import echart
products = Faker.choose()
dfs = []
for year in (2012, 2013, 2014, 2015):
dfs.append(
pd.DataFrame(
zip(products, Faker.values(), Faker.values(), [year]*len(products)),
columns=["商品", "商家A", "商家B", "年份"]
)
)
df = pd.concat(dfs, axis=0)
df.head()
| 商品 | 商家A | 商家B | 年份 | |
|---|---|---|---|---|
| 0 | 衬衫 | 124 | 69 | 2012 |
| 1 | 毛衣 | 98 | 45 | 2012 |
| 2 | 领带 | 140 | 45 | 2012 |
| 3 | 裤子 | 112 | 70 | 2012 |
| 4 | 风衣 | 142 | 71 | 2012 |
商家A总销量与年份的关系
df.echart.line("年份", "商家A", agg_func="sum", xtype="category", smooth=True).render_notebook()
所有商家总销量与年份的关系
df.echart.line("年份", ["商家A", "商家B"], agg_func="sum", xtype="category").render_notebook()
主题设置
df.echart.line("年份", ["商家A", "商家B"], agg_func="sum", xtype="category", theme="light").render_notebook()
多个Y轴显示
df.echart.line("年份", ["商家A", "商家B"], agg_func="sum", xtype="category", multiple_yaxis=True).render_notebook()
不同商品在所有商家的年销量
df.echart.line("年份", ["商家A", "商家B"], xtype="category", by="商品", multiple_yaxis=True).render_notebook()
将不同商品作为时间轴来显示
df.echart.line("年份", ["商家A", "商家B"], xtype="category", timeline="商品").render_notebook()