1.第一个图表示例
from pyecharts import Bar
import pandas as pd
import numpy as np
bar = Bar("我的第一个图表", "这里是副标题")
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
bar.print_echarts_options()
bar.render(r"e:\my_first_chart.html")
2.导入表格做图
from pyecharts import Bar
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\数据可视化测试.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
bar = Bar("测试图表", "瞎写写")
bar.add("ceshi", df_show.快递类别,df_show.状态)
bar.print_echarts_options()
bar.render(r"e:\my_second_chart.html")
3.两个图做对比
from pyecharts import Bar
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\数据可视化测试.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
bar = Bar("测试图表", "瞎写写")
bar.add("ceshi", df_show.快递类别,df_show.状态,,is_more_utils=True)
bar.add("ceshi2", df_show.快递类别,df_show.状态,,is_more_utils=True)
bar.print_echarts_options()
bar.render(r"e:\my_second_chart.html")
含注释版本–
from pyecharts import Bar
import pandas as pd
import numpy as np #导入包
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\数据可视化测试.xlsx',encoding='gb2312') #导入文件
df.head() #预览默认5行
df_show=pd.DataFrame(df) #创建DataFrame
bar = Bar("测试图表", "瞎写写") #图表主标题,副标题
bar.add("ceshi", df_show.快递类别,df_show.状态) #x轴快递类别,y轴状态数量
bar.print_echarts_options() #展示
bar.render(r"e:\my_second_chart.html") #输出的链接,在浏览器打开链接查看
4.柱状图上加平均线,加特殊值标注(最大,最小)
from pyecharts import Bar
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\数据可视化测试.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
bar = Bar("测试图表", "瞎写写")
bar.add("ceshi", df_show.快递类别,df_show.状态,mark_line=["average"],mark_point=["max","min"],is_more_utils=True)
bar.add("ceshi2", df_show.快递类别,df_show.状态,is_more_utils=True)
bar.print_echarts_options()
bar.render(r"e:\my_second_chart.html")
读取多个工作表的时候
data=pd.read_excel(catering_data,sheetname=0,index_col=u'日期')
5.多种图表结合
from pyecharts import Bar,Line,Overlap
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\数据可视化展示.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
bar = Bar("测试图表", "瞎写写")
bar.add("ceshi", df_show.日期,df_show.销售额,mark_line=["average"],mark_point=["max","min"])
line=Line()
line.add("ceshi2", df_show.日期,df_show.退款率)
overlap=Overlap()
overlap.add(bar)
overlap.add(line)
overlap.render(r"e:\my_多种图表_chart.html")
6.折线图
from pyecharts import Line
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\美西退货情况.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
line=Line("退货情况", "美西仓库")
line.add("包裹数", df_show.退货日期,df_show.包裹数,mark_line=["average"],mark_point=["max","min"],is_more_utils=True)
line.add("件数", df_show.退货日期,df_show.件数,mark_point=["max","min"],is_more_utils=True)
line.render(r"e:\my_退货_chart.html")
7.时间轴滑动显示效果
from pyecharts import Line
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\美西退货情况.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
line=Line("退货情况", "美西仓库")
line.add("包裹数", df_show.退货日期,df_show.包裹数,mark_line=["average"],mark_point=["max","min"],is_more_utils=True,is_datazoom_show=True) #is_datazoom_show=True 默认滑动显示效果
line.add("件数", df_show.退货日期,df_show.件数,mark_point=["max","min"],is_more_utils=True,is_label_show=True) #is_label_show=True 默认显示数据标签
line.render(r"e:\my_退货_chart.html")
8.组合图
from pyecharts import Line,Bar,Grid,Pie
import pandas as pd
import numpy as np
import pandas as pd
import numpy as np
df=pd.read_excel('C:\\Users\\lingtian\\Desktop\\美西退货情况.xlsx',encoding='gb2312')
df.head()
df_show=pd.DataFrame(df)
line=Line("退货情况", "美西仓库")
line.add("包裹数", df_show.退货日期,df_show.包裹数,mark_line=["average"],mark_point=["max","min"],is_more_utils=True)
line.add("件数", df_show.退货日期,df_show.件数,mark_point=["max","min"],is_more_utils=True)
bar=Bar("退货情况", "美西仓库")
bar.add("包裹数", df_show.退货日期,df_show.包裹数,mark_line=["average"],mark_point=["max","min"],is_more_utils=True)
bar.add("件数", df_show.退货日期,df_show.件数,mark_point=["max","min"],is_more_utils=True)
grid=Grid()
grid.add(line,grid_right="55%")
grid.add(bar,grid_left="60%")
grid.render(r"e:\my_退货_chart.html")