目录

Python-数据可视化Pyecharts三绘图二涟漪散点图,K线图,漏斗图,雷达图,词云图,地图,柱状图折线图组合,时间线轮廓图

Python—-数据可视化(Pyecharts三:绘图二:涟漪散点图,K线图,漏斗图,雷达图,词云图,地图,柱状图折线图组合,时间线轮廓图)

1、涟漪特效散点图

from pyecharts.globals import SymbolType from pyecharts.charts import EffectScatter from pyecharts.faker import Faker from pyecharts import options as opts from pyecharts.globals import ThemeType

绘制图表

es = ( EffectScatter(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE)) .add_xaxis(Faker.choose()) .add_yaxis(’’,Faker.values(),symbol=SymbolType.DIAMOND,symbol_size=20) )

渲染图表

es.render_notebook() https://i-blog.csdnimg.cn/direct/161dd33ef17a4ded97b848808d935997.png

2、K线图

from pyecharts.charts import Kline from pyecharts import options as opts data = [ [2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22], ]

绘制图表

kl = ( Kline() .add_xaxis([f'2030/6/{i}’ for i in range(1,len(data)+1)]) .add_yaxis(’’,data) )

渲染图表

kl.render_notebook() https://i-blog.csdnimg.cn/direct/b97fb65088ff45f2859fa2dc66d1c7e1.png

3、漏斗图

from pyecharts.charts import Funnel from pyecharts.faker import Faker from pyecharts import options as opts fun = ( Funnel() .add(’’,data_pair=[(k,v) for k,v in zip(Faker.choose(),Faker.values())], label_opts= opts.LabelOpts(formatter=’{b}:{c}’,position=‘inside’), sort_=‘ascending’ ) ) fun.render_notebook() https://i-blog.csdnimg.cn/direct/13681ed3de3548cea00542c9b6222e16.png

4、雷达图

from pyecharts.charts import Radar from pyecharts import options as opts #添加数据项 data1=[[98,100,89,89,97]] data2 = [[100,89,79,67,61]] #绘制雷达图 radar = ( Radar() .add_schema( [ opts.RadarIndicatorItem(name=“语文”,max_=100), opts.RadarIndicatorItem(name=“数学”,max_=100), opts.RadarIndicatorItem(name=“化学”,max_=100), opts.RadarIndicatorItem(name=“历史”,max_=100), opts.RadarIndicatorItem(name=“地理”,max_=100), ]) .add(‘小明’,data1,color=Faker.rand_color()) .add(‘大虎’,data2,color=Faker.rand_color()) .set_series_opts(label_opts=opts.LabelOpts(is_show=False),linestyle_opts=opts.LineStyleOpts(width=3)) ) radar.render_notebook() https://i-blog.csdnimg.cn/direct/8b3544c841ff4a40a2f16225330536ae.png

5、词云图

from pyecharts.charts import WordCloud from pyecharts import options as opts data = [ [‘ThinkPad’,‘15.7’], [‘联想’,‘14.5’], [‘惠普’,‘14.4’], [‘华为’,‘11.7’], [‘华硕’,‘8.2’], [‘戴尔’,‘8.1’], [‘Acer 宏碁’,‘4.5’], [‘苹果’,‘3.5’], [‘神舟’,‘3.2’], [‘ROG’,‘3.1’], [‘机械革命’,‘2.4’], [‘msi 微星’,‘1.8’], [‘外星人’,‘1.5’], [‘微软’,‘1.4’], [‘荣耀’,‘1.2’], [‘雷神’,‘1’], [‘三星’,‘0.7’], [‘红米’,‘0.6’], [‘机械师’,‘0.5’], [‘小米’,‘0.5’], [‘炫龙’,‘0.4’], [‘雷蛇’,‘0.2’], [‘壹号本’,‘0.1’], [‘a 豆’,‘0.1’], [‘未来人类’,‘0.1’], [‘技嘉’,‘0.1’], [‘中柏’,‘0.1’], [‘VAIO’,‘0.1’], [‘火影’,‘0.1’], [‘LG’,‘0.1’], [‘松下’,‘0’], [‘麦本本’,‘0’], [‘吾空’,‘0’], [‘长城’,‘0’], [‘GPD’,‘0’], [‘清华同方’,‘0’], [‘神基’,‘0’], [‘爱尔轩’,‘0’], [‘酷比魔方’,‘0’], [‘海尔’,‘0’], [‘谷歌’,‘0’], [‘台电’,‘0’], [‘iru’,‘0’], [‘攀升 IPASON’,‘0’], [‘NEC’,‘0’], [‘夏普’,‘0’], [‘京东京造’,‘0’], [‘锡恩帝’,‘0’], [‘皓勤’,‘0’], [‘Intel’,‘0’]]

绘制指定图形

wd = ( WordCloud() # 初始化词云图表 .add(’’,data,shape=‘star’) )

渲染图表

wd.render_notebook() https://i-blog.csdnimg.cn/direct/d11fc07488a84fb38b2a22149a1c4fe8.png

6、地图

from pyecharts.charts import Map from pyecharts import options as opts from pyecharts.faker import Faker map = ( Map() # 初始化地图对象 .add(‘商家A’,[[‘北京市’,100],[‘上海市’,150],[‘太原市’,99]],‘china’)

1. 数据的key一定要和地图上的名称相符

2. 地图上没有的key尽量不要去用,很有可能显示不出来

)

渲染图表

map.render_notebook() https://i-blog.csdnimg.cn/direct/59a351e1b3914a95a6cfdffeeb004a2d.png

地图坐标图 from pyecharts.charts import Geo from pyecharts.faker import Faker from pyecharts import options as opts from pyecharts.globals import ChartType from pyecharts.globals import SymbolType geo = ( Geo() .add_schema() .add(’’,data_pair=[i for i in zip(Faker.provinces,Faker.values())], label_opts= opts.LabelOpts(is_show=False), type_=ChartType.EFFECT_SCATTER) # 填充数据 .add(’’,[(‘北京’,‘上海1’),(‘北京’,‘广州’),(‘广州’,‘上海’)], type_=ChartType.LINES, # 绘制成线 linestyle_opts=opts.LineStyleOpts(curve=0.2), # 设置线的平滑度 effect_opts=opts.EffectOpts(symbol_size=6,symbol=SymbolType.ARROW,color=‘green’), color=‘green’ ) )

渲染图表

geo.render_notebook() https://i-blog.csdnimg.cn/direct/68a80ac9c644452389eb2011cc8d709a.png

7、柱状图折线图组合

from pyecharts.charts import Bar,Line from pyecharts.globals import ThemeType from pyecharts import options as opts

设置数据

x_value = [f’{i}月’ for i in range(1,13)]

蒸发

evaporation = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]

降水

precipitation = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]

温度

temperature = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]

柱状图

bar = ( Bar() .add_xaxis(xaxis_data=x_value) # 设置x轴数据 .add_yaxis(‘蒸发’,evaporation) .add_yaxis(‘降水’,precipitation) .set_global_opts(title_opts=opts.TitleOpts(‘组合图’), yaxis_opts=opts.AxisOpts(name=‘水量’,min_=0,max_=250, axislabel_opts=opts.LabelOpts(formatter=’{value}ml’))) .extend_axis(yaxis=opts.AxisOpts( name=‘温度’,min_=0,max_=25, axislabel_opts=opts.LabelOpts(formatter=’{value}℃’) )) # 追加y轴数据 )

折线图

line = ( Line() .add_xaxis(xaxis_data=x_value) .add_yaxis(‘温度’,temperature,yaxis_index=1) # yaxis_index指定第几个y轴内容 )

混合2个图表

bar.overlap(line)

渲染图表

bar.render_notebook() https://i-blog.csdnimg.cn/direct/b94cc037ae694eb7aa6eccb193d9ce16.png

8、时间线轮播图

from pyecharts.charts import Timeline,Bar from pyecharts.faker import Faker

绘制时间线图表

timeline = Timeline()

设置x轴数据

x_value = Faker.choose() for year in range(2020,2031): bar = ( Bar() .add_xaxis(x_value) .add_yaxis(‘商家A’,Faker.values()) .add_yaxis(‘商家B’,Faker.values()) )

将图表增加到时间线中

timeline.add(bar,f’{year}年’)

渲染图表

timeline.render_notebook() https://i-blog.csdnimg.cn/direct/41eda1510d314b12b0610483479d3f10.png