您好,登錄后才能下訂單哦!
這篇文章主要講解了python中pyecharts如何實現一個文件繪制多張圖,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。
Grid并行顯示多張圖
注意: 第一個圖需為 有 x/y 軸的圖,即不能為 Pie,其他位置順序任意
from pyecharts import Bar, Line, Scatter, EffectScatter, Grid ''' Grid類:并行顯示多個圖表 TODO 第一個圖需為 有 x/y 軸的圖,即不能為 Pie,其他位置順序任意。 ''' attr = ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱狀圖示例", title_pos="65%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_pos="80%") line = Line("折線圖示例") attr = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] line.add( "最高氣溫", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低氣溫", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", ) v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter("散點圖示例", title_top="50%", title_pos="65%") scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%") es = EffectScatter("動態散點圖示例", title_top="50%") es.add( "es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_top="50%", legend_pos="20%", ) # TODO 配置Grid類 grid = Grid(height=720, width=1200) # 初始化,參數可傳page_title,width,height grid.add(bar, grid_bottom="60%", grid_left="60%") # 添加要展示的圖表,并設置顯示位置 grid.add(line, grid_bottom="60%", grid_right="60%") # 添加要展示的圖表,并設置顯示位置 grid.add(scatter, grid_top="60%", grid_left="60%") # 添加要展示的圖表,并設置顯示位置 grid.add(es, grid_top="60%", grid_right="60%") # 添加要展示的圖表,并設置顯示位置 grid.render("./pyecharts_html/Grid_并行顯示多張圖表.html")
overlap圖表混合使用
from pyecharts import Line, Bar, Overlap ''' 多個x y軸示例 ''' attr = ["{}月".format(i) for i in range(1, 13)] v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3] v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3] v3 = [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() bar.add("蒸發量", attr, v1) bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_interval=50, yaxis_max=250) line = Line() line.add("平均溫度", attr, v3, yaxis_formatter=" °C", yaxis_interval=5) overlap = Overlap(width=1200, height=600) # 實例化 # 默認不新增 x y 軸,并且 x y 軸的索引都為 0 overlap.add(bar) # 新增一個 y 軸,此時 y 軸的數量為 2,第二個 y 軸的索引為 1(索引從 0 開始),所以設置 yaxis_index = 1 # 由于使用的是同一個 x 軸,所以 x 軸部分不用做出改變 overlap.add(line, yaxis_index=1, is_add_yaxis=True) overlap.render("./pyecharts_html/Overlap_圖表混合.html")
Page一個頁面順序渲染多個圖表
from pyecharts import * page = Page() # 實例化page類 # line attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line = Line("折線圖示例") line.add("最高氣溫", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低氣溫", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"]) page.add(line) # TODO 向page中添加圖表 # pie attr = ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("餅圖-圓環圖示例", title_pos='center') pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') page.add(pie) # TODO 向page中添加圖表 # kline v1 = [[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]] kline = Kline("K 線圖示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1) page.add(kline) # TODO 向page中添加圖表 # radar schema = [ ("銷售", 6500), ("管理", 16000), ("信息技術", 30000), ("客服", 38000), ("研發", 52000), ("市場", 25000) ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷達圖示例") radar.config(schema) radar.add("預算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("實際開銷", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') page.add(radar) # TODO 向page中添加圖表 page.render("./pyecharts_html/Page_一個頁面渲染多張圖表.html")
Timeline:時間線輪播多圖
from pyecharts import Bar, Line, Timeline, Overlap from random import randint attr = ["{}月".format(i) for i in range(1, 7)] bar = Bar("1 月份數據", "數據純屬虛構") bar.add("bar", attr, [randint(10, 50) for _ in range(6)]) line = Line() line.add("line", attr, [randint(50, 80) for _ in range(6)]) overlap = Overlap() overlap.add(bar) overlap.add(line) bar_1 = Bar("2 月份數據", "數據純屬虛構") bar_1.add("bar", attr, [randint(10, 50) for _ in range(6)]) line_1 = Line() line_1.add("line", attr, [randint(50, 80) for _ in range(6)]) overlap_1 = Overlap() overlap_1.add(bar_1) overlap_1.add(line_1) bar_2 = Bar("3 月份數據", "數據純屬虛構") bar_2.add("bar", attr, [randint(10, 50) for _ in range(6)]) line_2 = Line() line_2.add("line", attr, [randint(50, 80) for _ in range(6)]) overlap_2 = Overlap() overlap_2.add(bar_2) overlap_2.add(line_2) bar_3 = Bar("4 月份數據", "數據純屬虛構") bar_3.add("bar", attr, [randint(10, 50) for _ in range(6)]) line_3 = Line() line_3.add("line", attr, [randint(50, 80) for _ in range(6)]) overlap_3 = Overlap() overlap_3.add(bar_3) overlap_3.add(line_3) bar_4 = Bar("5 月份數據", "數據純屬虛構") bar_4.add("bar", attr, [randint(10, 50) for _ in range(6)]) line_4 = Line() line_4.add("line", attr, [randint(50, 80) for _ in range(6)]) overlap_4 = Overlap() overlap_4.add(bar_4) overlap_4.add(line_4) timeline = Timeline( page_title = "頁標簽名", width=600, height=600, is_auto_play= True, # 是否自動播放,默認=False is_loop_play= True, # 是否循環播放 is_rewind_play=False, # 反向播放 is_timeline_show=True, # 是否顯示時間線,默認=true timeline_play_interval=1000, # 播放間隔,ms timeline_symbol= "arrow", # 時間點標記圖形, 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow' timeline_symbol_size= [15,8], # 圖形大小,可以是數字和列表,列表表示寬高 timeline_left= "1% ", # 距離左邊距離 , timeline_right timeline_bottom=0, # timeline_top ) timeline.add(overlap, '1 月') timeline.add(overlap_1, '2 月') timeline.add(overlap_2, '3 月') timeline.add(overlap_3, '4 月') timeline.add(overlap_4, '5 月') timeline.render("./pyecharts_html/Timeline_時間線輪播多張圖表.html")
看完上述內容,是不是對python中pyecharts如何實現一個文件繪制多張圖有進一步的了解,如果還想學習更多內容,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。