2014-12-19 2 views
3

나는 간단한 matplotlib 히스토그램을 가지고 있으며 몇개의 숫자로 ylabels을 나눌 필요가있다. 예를 들어 1, 2, 3이 필요한데 100 200 200 300입니다. 제안이 있습니까?ytics를 matplotlib의 특정 숫자로 나누는 방법은 무엇입니까?

import numpy 
import matplotlib 
# Turn off DISPLAY 
matplotlib.use('Agg') 
import pylab 

# Figure aspect ratio, font size, and quality 
matplotlib.pyplot.figure(figsize=(100,50),dpi=400) 
matplotlib.rcParams.update({'font.size': 150}) 

matplotlib.rcParams['xtick.major.pad']='68' 
matplotlib.rcParams['ytick.major.pad']='68' 


# Read data from file 
data=pylab.loadtxt("data.txt") 

# Plot a histogram 
n, bins, patches = pylab.hist(data, 50, normed=False, histtype='bar') 
#matplotlib.pyplot.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1) 

# Axis labels 
pylab.xlabel('# of Occurence') 
pylab.ylabel('Signal Probability') 

# Save in PDF file 
pylab.savefig("Output.pdf", dpi=400, bbox_inches='tight', pad_inches=1) 
+0

문제점을 설명해주십시오. –

답변

3

이 단순히 형식 문제입니다 당신이 기본 데이터를 변경하지 않으려는 것으로 나타나고 :

여기 내 코드입니다. 이 경우 ticker module에있는 formatter-function class의 인스턴스를 사용할 수 있습니다.

포매터 기능 - 포맷터 기능 클래스의 인스턴스와 함께 사용되는 - 포매터 기능 클래스는 틱 레이블 및 틱 위치의 두 인수를 취하여 서식이 지정된 눈금 레이블을 반환합니다. 다음은 귀하의 목적을위한 것입니다.

def numfmt(x, pos): # your custom formatter function: divide by 100.0 
    s = '{}'.format(x/100.0) 
    return s 

import matplotlib.ticker as tkr  # has classes for tick-locating and -formatting 
yfmt = tkr.FuncFormatter(numfmt) # create your custom formatter function 

# your existing code can be inserted here 

pylab.gca().yaxis.set_major_formatter(yfmt) 

# final step 
pylab.savefig("Output.pdf", dpi=400, bbox_inches='tight', pad_inches=1) 
관련 문제