加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – matplotlib中的背对背直方图

发布时间:2020-12-20 11:11:38 所属栏目:Python 来源:网络整理
导读:有一个很好的功能,在Matlab中绘制 back to back histograms.我需要在matplotlib中创建一个类似的图形.有谁能展示一个有效的代码示例? 解决方法 感谢Mark Rushakoff指出的链接,以下是我最终做的事情 import numpy as npfrom matplotlib import pylab as plda
有一个很好的功能,在Matlab中绘制 back to back histograms.我需要在matplotlib中创建一个类似的图形.有谁能展示一个有效的代码示例?

解决方法

感谢Mark Rushakoff指出的链接,以下是我最终做的事情

import numpy as np
from matplotlib import pylab as pl

dataOne = get_data_one()
dataTwo = get_data_two()

hN = pl.hist(dataTwo,orientation='horizontal',normed=0,rwidth=0.8,label='ONE')
hS = pl.hist(dataOne,bins=hN[1],label='TWO')

for p in hS[2]:
    p.set_width( - p.get_width())

xmin = min([ min(w.get_width() for w in hS[2]),min([w.get_width() for w in hN[2]]) ])
xmin = np.floor(xmin)
xmax = max([ max(w.get_width() for w in hS[2]),max([w.get_width() for w in hN[2]]) ])
xmax = np.ceil(xmax)
range = xmax - xmin
delta = 0.0 * range
pl.xlim([xmin - delta,xmax + delta])
xt = pl.xticks()
n = xt[0]
s = ['%.1f'%abs(i) for i in n]
pl.xticks(n,s)
pl.legend(loc='best')
pl.axvline(0.0)
pl.show()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读