matplotlib中的背对背直方图 [英] back-to-back histograms in matplotlib

查看:77
本文介绍了matplotlib中的背对背直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个很好的函数可以在Matlab中绘制背对背直方图.我需要在matplotlib中创建一个类似的图形.任何人都可以显示一个有效的代码示例吗?

There is a nice function that draws back to back histograms in Matlab. I need to create a similar graph in matplotlib. Can anyone show a working code example?

推荐答案

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

Thanks to the link pointed by Mark Rushakoff, following is what I finally did

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], orientation='horizontal', normed=0, 
    rwidth=0.8, 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()

这篇关于matplotlib中的背对背直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆