문제

그리는 좋은 기능이 있습니다 뒤로 히스토그램 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()

다른 팁

이것 matplotlib 사용자 메일 링 게시물 A에 대한 샘플 코드가 있습니다 Bihistogram 그것은 왼쪽과 오른쪽 대신 위아래로갑니다. 예제 출력은 다음과 같습니다 그는 연결했다.

Up-Down이 절대적으로 작동하지 않으면 y 축의 작업을 X 축 작업과 교환하는 데 몇 분 밖에 걸리지 않아야합니다.

또한 링크는 MATLAB 기능이 아니며 누군가가 약 40 줄로 쓴 실제 스크립트입니다. matlab과 matplotlib가 상당히 가까운 구문을 가지고 있기 때문에 실제로 스크립트 소스를보고 포팅을 시도 할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top