水平条形图与绘制柱状图类似,大家可以先看看我之前写的博客,如何绘制柱状图

水平条形图需要在Bar函数中设置orientation= 'h'

其他的参数与柱状图相同。也可以通过设置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=['资产1', '资产2', '资产3'],
orientation = 'h'
)]
layout = go.Layout(
title = '净资产收益率对比'
)
figure = go.Figure(data = data, layout = layout)
pyplt(figure, filename='tmp/1.html')

运行上述代码,得到如上图所示的图例,可以看到其画法跟柱状图一样,只是变成水平方向。

如何画水平的层叠条形图,只需要我们将参数,barmode = 'stack',即可画出响应的水平图

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')

运行上述代码,可以得到如上图所示的层叠水平条形图。

水平条形图和柱状图的画法基本上相同。剩下的就不细讲了。

Python使用Plotly绘图工具,绘制水平条形图的更多相关文章

  1. Python使用Plotly绘图工具,绘制直方图

    今天我们再来讲解一下Python使用Plotly绘图工具如何绘制直方图 使用plotly绘制直方图需要用到graph_objs包中的Histogram函数 我们将数据赋值给函数中的x变量,x = da ...

  2. Python使用Plotly绘图工具,绘制面积图

    今天我们来讲一下如何使用Python使用Plotly绘图工具,绘制面积图 绘制面积图与绘制散点图和折线图的画法类似,使用plotly graph_objs 中的Scatter函数,不同之处在于面积图对 ...

  3. Python使用Plotly绘图工具,绘制饼图

    今天我们来学习一下如何使用Python的Plotly绘图工具,绘制饼图 使用Plotly绘制饼图的方法,我们需要使用graph_objs中的Pie函数 函数中最常用的两个属性values,用于赋值给需 ...

  4. Python使用Plotly绘图工具,绘制甘特图

    今天来讲一下如何使用Python 的绘图工具Plotly来绘制甘特图的方法 甘特图大家应该了解熟悉,就是通过条形来显示项目的进度.时间安排等相关情况的. 我们今天来学习一下,如何使用ployly来绘制 ...

  5. Python使用Plotly绘图工具,绘制气泡图

    今天来讲讲如何使用Python 绘图工具,Plotly来绘制气泡图. 气泡图的实现方法类似散点图的实现.修改散点图中点的大小,就变成气泡图. 实现代码如下: import plotly as py i ...

  6. Python使用Plotly绘图工具,绘制散点图、线形图

    今天在研究Plotly绘制散点图的方法 使用Python3.6 + Plotly Plotly版本2.0.0 在开始之前先说说,还需要安装库Numpy,安装方法在我的另一篇博客中有写到:https:/ ...

  7. Python使用Plotly绘图工具,绘制柱状图

    使用Plotly绘制基本的柱状图,需要用到的函数是graph_objs 中 Bar函数 通过参数,可以设置柱状图的样式. 通过barmod进行设置可以绘制出不同类型的柱状图出来. 我们先来实现一个简单 ...

  8. Plotly绘图工具(多用于统计)

    作者:桂. 时间:2017-04-23  23:52:14 链接:http://www.cnblogs.com/xingshansi/p/6754769.html 前言 无意中考到一个小工具,网址为: ...

  9. 小白学Python(13)——pyecharts 绘制 柱状图/条形图 Bar

    Bar-基本示例 from example.commons import Faker from pyecharts import options as opts from pyecharts.char ...

随机推荐

  1. [Swift]LeetCode205. 同构字符串 | Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  2. [Swift]LeetCode302. 包含黑色像素的最小矩形 $ Smallest Rectangle Enclosing Black Pixels

    An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...

  3. [Swift]LeetCode371. 两整数之和 | Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  4. Firefox 多行标签的解决方案分享

    更新了 Quantum 以后 TabMixPlus 就不能用了,我最中意的多行标签也没了,捣鼓了一下终于重新回来了. 指南: https://discourse.mozilla.org/t/tabs- ...

  5. eclipse菜单栏不显示 + the system is running in lou-graphics mode问题

    作为一个Linux使用新手,一条指令执行下去,就可能是一堆的错误.这不,笔者在Ubuntu16.04上安装eclipse后没有菜单栏,用起来不是很方便,网上找一篇老师写的博客ubuntu 中 ecli ...

  6. SpringBoot环境搭建

    创建 maven 项目 , 选择的打包类型为 jar 类型 自己构建 SpringBoot 项目时 , 要继承 SpringBoot 的父项目 , 这里用的版本是 2.1.4 点击 Finish , ...

  7. Linux~常用的命令

    大叔学Linux就一个目的,部署在它上面的服务,如redis,mongodb,fastDFS,cat,docker,mysql,nginx等 下面找一下的命令,来学学这个神秘的操作系统 常用指令 ls ...

  8. 如何零基础开始自学Python编程

    转载——原作者:赛门喵 链接:https://www.zhihu.com/question/29138020/answer/141170242 0. 明确目标 我是真正零基础开始学Python的,从一 ...

  9. centos 7 linux系统安装 mysql5.7.17(glibc版)

    前言:经过一天半的折腾,终于把 mysql 5.7.17 版本安装上了 centos 7 系统上,把能参考的博客几乎都看了一遍,终于发现这些细节问题,然而翻了无数的文章,基本上都没有提到这些,所以小生 ...

  10. PC逆向之代码还原技术,第四讲汇编中减法的代码还原

    目录 PC逆向之代码还原技术,第四讲汇编中减法的代码还原 一丶汇编简介 二丶高级代码对应汇编观看. 1.代码还原解析: 三丶根据高级代码IDA反汇编的完整代码 四丶知识总结 PC逆向之代码还原技术,第 ...