关于时间数据类型的可视化(pyecharts0.5.x)以及pyecharts基本使⽤--超级详
细
要使⽤pyecharts0.5.x之前,再次强调pyecharts0.5.x和pyecharts1.x的使⽤区别:
pyecharts0.5.x 中 以图例为主体,需要什么就add什么就好了,⼀般在add⾥⾯直接写需要的功能的参数就ok了。
pyecharts1.x中以options对象为主体,万物皆oop,可以通过不断的在对象上调⽤⽅法就 了。
这篇是关于pycharts-0.5.x版本的可视化,如果你想使⽤最新版的1.7.0版本,以及分清楚这两个版本的区别,可以具体详见另⼀篇⽂章:
⾸先,⼀般来说,⼩数据的话作为列表传⼊就可以搞定。但是pycharts05x还是⽀持其它类型的数据传⼊的,⽐如numpy的数组。具体介绍看这⾥:
进⼊虚拟环境(),进⾏安装pycharts0.5.x版本:(如果速度慢的话可以换pip源)
pip install pyecharts==0.5.11
⼀、时间数据可视化
(⼀)、连续型时间数据可视化
1.阶梯图
from pyecharts import Line
#1.实例化⼀个图例(其实就是实例化对象,调⽤了⼀个构造函数,返回⼀个对象)
line = Line("折线图-阶梯图-1713406107")
# 2.构造适合pycharts能读取的数据(我这⾥是美国某些年的邮票数据)
datax =['1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009']
datay =[0.32,0.32,0.32,0.32,0.33,0.33,0.34,0.37,0.37,0.37,0.37,0.39,0.41,0.42,0.44]
#3.向图例中添加数据以及配置
line.add("邮票", datax, datay, is_step=True, is_label_show=True,)
#4.打印图表保存
line #直接在jupyter notebook上⾯打印显⽰
#der_notebook() #直接在jupyter notebook上⾯打印显⽰
# der(path="阶梯图-美国邮票价格.html") #将图作为html⽂件保存起来,当然也可以作为图⽚格式保存起来。
注意 :
关于pycharts05x画图的步骤在上⾯的代码的注释中! 0.5.x版本参考1》2》3》4 这四个步骤即可完成基本画图。具体的⼀些个性化配置可以查看⽂档:
2.折线图
from pyecharts import Line
df = pd.read_csv("world-population.csv")
df.Year = df.Year.astype(str)
line = Line("折线图-世界⼈⼝")
line.add(
"⼈⼝",
list(df.Year),
list(df.Population),
mark_point=["max","min"],肉是酸性还是碱性
)
董志成line
3 拟合曲线
from pyecharts import Overlap,Scatter,Line
rate = pd.read_csv(u"unemployment-rate-1948-2010.csv") year =list(rate.Year.astype(str))
value =list(rate.Value)
sc = Scatter()
sc.add("", year, value, effect_scale=5)
poly = np.polyfit(list(rate.Year), value, deg =3)
y =list(np.polyval(poly,list(rate.Year)))#计算所有点
line = Line("失业率趋势")
line.add("趋势",year,y)
礼仪活动overlap = Overlap()
overlap.add(line)
overlap.add(sc)
overlap
(⼆)、离散型时间数据可视化
1. 散点图
from pyecharts import Scatter
subscribers = pd.read_csv('subscribers.csv')
suber = subscribers.Subscribers
喝早茶day = subscribers.Date
day =[i[3:5]for i in list(day)]
电脑显卡怎么看
sc = Scatter("订阅数量图")
sc.add("Subscribers",day,list(suber))
sc
2.柱形图
from pyecharts import Bar
# 热狗⼤胃王⼤赛成绩
hotdog = pd.read_csv("hot-dog-contest-winners.csv")
year =list(hotdog.Year.astype(str))
value_count =list(hotdog['Dogs eaten'])
bar = Bar("30年热狗⼤赛成绩单")
bar.add("Winer吃掉的热狗数量", year,value_count, mark_line=["average"], mark_point=["max","min"]) bar
3. 堆叠柱形图
# 数据⽬测还是⼤胃王
from pyecharts import Bar
hotplace = pd.read_csv("hot-dog-places.csv",header=None)
hotplace = pd.DataFrame(hotplace.values.T, lumns,columns=['year','A','B','C']) year =ar.astype(str))
bar = Bar("堆叠珠柱状图显⽰⼤胃王成绩")
bar.add("A", year,list(hotplace.A), is_stack=True)
bar.add("B", year,list(hotplace.B), is_stack=True)
bar.add("C", year,list(hotplace.C), is_stack=True)
bar
对于3:更加直观的对⽐:
百合种植from pyecharts import Bar
year =ar.astype(str))
bar = Bar("直观对⽐显⽰⼤胃王成绩")
bar.add("A", year,list(hotplace.A),mark_point=["max","min"],mark_line=["average"])
bar.add("B", year,list(hotplace.B),mark_point=["max","min"],mark_line=["average"])
梅花功效bar.add("C", year,list(hotplace.C),mark_point=["max","min"],mark_line=["average"])
焗生蚝bar