Fork me on GitHub

plotly-express-23-绘制水平柱状图

Plotly-express-23-绘制水平柱状图

本文中介绍的是如何利用Plotly_express绘制水平方向的柱状图

  • 单组水平柱状图
  • 多组水平柱状图

单组水平柱状图

效果

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import plotly as py
import plotly.graph_objs as go

data = [go.Bar(
x=[21, 38, 30],
y=['小明', '小红', '小军'],
orientation = 'h' # 改成h
)]
layout = go.Layout(
title = '年龄'
)
fig = go.Figure(data = data, layout = layout)

fig.show()

多组水平柱状图

效果

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import plotly as py
import plotly.graph_objs as go

pyplt = py.offline.plot
trace1 = go.Bar(
y = ['语文', '数学', '英语'],
x = [88, 79, 86],
name = '张三',
orientation = 'h',
marker = dict(
color = '#104E8B',
line = dict(
color = '#104E8B',
width = 3)
)
)
trace2 = go.Bar(
y = ['语文', '数学', '英语'],
x = [98, 75, 63],
name = '小明',
orientation = 'h',
marker = dict(
color = '#1874CD',
line = dict(
color = '#104E8B',
width = 3)
)
)
trace3 = go.Bar(
y = ['语文', '数学', '英语'],
x = [79, 88, 97],
name = '小军',
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)
fig.show()

本文标题:plotly-express-23-绘制水平柱状图

发布时间:2021年03月17日 - 09:03

原始链接:http://www.renpeter.cn/2021/03/17/plotly-express-23-%E7%BB%98%E5%88%B6%E6%B0%B4%E5%B9%B3%E6%9F%B1%E7%8A%B6%E5%9B%BE.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea