欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python使用Plotly繪圖工具繪制水平條形圖

 更新時間:2020年03月25日 10:36:30   作者:成都-王帥  
這篇文章主要為大家詳細介紹了python使用Plotly繪圖工具繪制水平條形圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了python繪制水平條形圖的具體代碼,供大家參考,具體內(nèi)容如下

水平條形圖與繪制柱狀圖類似,大家可以先看看我之前寫的博客,如何繪制柱狀圖

水平條形圖需要在Bar函數(shù)中設(shè)置orientation= 'h'

其他的參數(shù)與柱狀圖相同。也可以通過設(shè)置barmode = 'stack',

繪制層疊水平條形圖和瀑布式水平條形圖

import plotly as py
import plotly.graph_objs as go
pyplt = py.offline.plot
data = [go.Bar(
  x=[29.41, 34.62, 30.16],
  y=['資產(chǎn)1', '資產(chǎn)2', '資產(chǎn)3'],
  orientation = 'h'
)]
layout = go.Layout(
  title = '凈資產(chǎn)收益率對比'
 )
figure = go.Figure(data = data, layout = layout)
pyplt(figure, filename='tmp/1.html')

運行上述代碼,得到如上圖所示的圖例,可以看到其畫法跟柱狀圖一樣,只是變成水平方向。

如何畫水平的層疊條形圖,只需要我們將參數(shù),barmode = 'stack',即可畫出響應(yīng)的水平圖

import plotly as py
import plotly.graph_objs as go
 
pyplt = py.offline.plot
trace1 = go.Bar(
 y = ['CU.SHF', 'AG.SHF', 'AU.SHF'],
 x = [21258, 30279, 8056],
 name = '期貨1',
 orientation = 'h',
 marker = dict(
 color = '#104E8B',
 line = dict(
  color = '#104E8B',
  width = 3)
 )
)
trace2 = go.Bar(
 y = ['CU.SHF', 'AG.SHF', 'AU.SHF'],
 x = [19853, 9375, 4063],
 name = '期貨2',
 orientation = 'h',
 marker = dict(
 color = '#1874CD',
 line = dict(
  color = '#104E8B',
  width = 3)
 )
)
trace3 = go.Bar(
 y = ['CU.SHF', 'AG.SHF', 'AU.SHF'],
 x = [4959, 13018, 8731],
 name = '期貨3',
 orientation = 'h',
 marker = dict(
 color = '#1C86EE',
 line = dict(
  color = '#104E8B',
  width = 3)
 )
)
 
data = [trace1, trace2,trace3]
layout = go.Layout(
 title = '稀有金屬期貨持倉量對比圖',
 barmode='stack'
)
 
fig = go.Figure(data=data, layout=layout)
pyplt(fig, filename='tmp/2.html')

運行上述代碼,可以得到如上圖所示的層疊水平條形圖。

水平條形圖和柱狀圖的畫法基本上相同。剩下的就不細講了。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論