2014-01-17 3 views
5

어떻게 든 X 축의 값을 matplotlib의 16 진수 표기법으로 인쇄 할 수 있습니까? 내 플롯의 경우 X 축은 메모리 주소를 나타냅니다.matplotlib의 16 진수 X 축?

감사합니다.

답변

5

축에 형식기를 설정할 수 있습니다 (예 : FormatStrFormatter).

간단한 예 :

import matplotlib.pyplot as plt 
import matplotlib.ticker as ticker 


plt.plot([10, 20, 30], [1, 3, 2]) 
axes = plt.gca() 
axes.get_xaxis().set_major_locator(ticker.MultipleLocator(1)) 
axes.get_xaxis().set_major_formatter(ticker.FormatStrFormatter("%x")) 
plt.show() 
+1

대단히 감사합니다. – user3207230

1

나는 때문에 유형 불일치의 오류를 얻을 64 비트 컴퓨터에 파이썬 3.5을 사용.

TypeError: %x format: an integer is required, not numpy.float64 

나는 그것을 정수로 변환 할 수있는 기능 포매터를 사용하여 주위를 얻었다.

import matplotlib.pyplot as plt 
import matplotlib.ticker as ticker 

def to_hex(x, pos): 
    return '%x' % int(x) 

fmt = ticker.FuncFormatter(to_hex) 

plt.plot([10, 20, 30], [1, 3, 2]) 
axes = plt.gca() 
axes.get_xaxis().set_major_locator(ticker.MultipleLocator(1)) 
axes.get_xaxis().set_major_formatter(fmt) 
plt.show() 
관련 문제