2012-05-22 2 views

답변

6

게시 품질 수치를 목표로하는 경우 축 레이블을 미세하게 제어해야합니다.

import pylab as plt 
import numpy as np 

# Create some random data over a large interval 
N = 200 
X = np.random.random(N) * 10 ** 6 
Y = np.sqrt(X) 

# Draw the figure to get the current axes text 
fig, ax = plt.subplots() 
plt.scatter(X,Y) 
ax.axis('tight') 
plt.draw() 

# Edit the text to your liking 
label_text = [r"$%i \cdot 10^4$" % int(loc/10**4) for loc in plt.xticks()[0]] 
ax.set_xticklabels(label_text) 

# Show the figure 
plt.show() 

enter image description here

3

당신은 과학적 표기법에 레이블 스타일을 설정하는 pyplot.ticklabel_format을 사용할 수 있습니다 :이 작업을 수행하는 한 가지 방법은 레이블 텍스트를 추출하여 사용자 정의 서식을 적용하는 것입니다.

import pylab as plt 
import numpy as np 

# Create some random data over a large interval 
N = 200 
X = np.random.random(N) * 10 ** 6 
Y = np.sqrt(X) 

# Draw the figure to get the current axes text 
fig, ax = plt.subplots() 
plt.scatter(X,Y) 
ax.axis('tight') 
plt.draw() 

plt.ticklabel_format(style='sci',axis='x',scilimits=(0,0)) 

# Edit the text to your liking 
#label_text = [r"$%i \cdot 10^4$" % int(loc/10**4) for loc in plt.xticks()[0]] 
#ax.set_xticklabels(label_text) 

# Show the figure 
plt.show() 

Output

관련 문제