gpt4 book ai didi

python - matplotlib 中的背靠背直方图

转载 作者:太空狗 更新时间:2023-10-30 02:23:50 26 4
gpt4 key购买 nike

有一个很好的函数可以绘制 back to back histograms在Matlab中。我需要在 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], 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()

关于python - matplotlib 中的背靠背直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1340338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com