3
기본적으로 matplotlib로 플롯을 생성 할 때 y 축의 눈금이 수백만 개로 나뉩니다. 1000000이 1,000,000으로 표시되도록 자릿수 그룹을 켜거나 소수 자릿수를 켜려면 어떻게해야합니까?Matplotlib 숫자 그룹 (소수 구분 기호)
기본적으로 matplotlib로 플롯을 생성 할 때 y 축의 눈금이 수백만 개로 나뉩니다. 1000000이 1,000,000으로 표시되도록 자릿수 그룹을 켜거나 소수 자릿수를 켜려면 어떻게해야합니까?Matplotlib 숫자 그룹 (소수 구분 기호)
여기에는 내장 기능이 없다고 생각합니다. (그게 내가 당신의 Q를 읽은 후에 생각한 것입니다, 나는 단지 체크했고 문서에서 찾을 수 없었습니다).
어떤 경우에도 나만의 것을 굴릴 수 있습니다.
(전체 예제입니다. 즉, 한 축에 공선 눈금 레이블이있는 mpl 플롯이 생성됩니다. 5 줄의 코드 만 있으면 사용자 지정 눈금 레이블을 만들 수 있습니다. 3 개 (import 문 포함)) 및 새 레이블을 만들고 지정된 축에 배치하는 두 줄을 두 줄로 표시합니다.)
# first code a function to generate the axis labels you want
# ie, turn numbers greater than 1000 into commified strings (12549 => 12,549)
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
fnx = lambda x : locale.format("%d", x, grouping=True)
from matplotlib import pyplot as PLT
import numpy as NP
data = NP.random.randint(15000, 85000, 50).reshape(25, 2)
x, y = data[:,0], data[:,1]
fig = PLT.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y, "ro")
default_xtick = range(20000, 100000, 10000)
# these two lines are the crux:
# create the custom tick labels
new_xtick = map(fnx, default_xtick)
# set those labels on the axis
ax1.set_xticklabels(new_xtick)
PLT.show()
다음과 같이 할 수 있습니다. http://tiku.io/questions/1009459/how-to-format-axis-number-format-to-thousand-comm-in-matplotlib –