2016-04-06 17 views
0

Y ekseni içinde yıl ve x ekseninde yıl gösteren bir grafik oluşturmak için aşağıdaki kodu kullanıyorum. Y eksenimi 4,000,000, 8,000,000, 12,000,000 ...matplot lib y ekseni dolar işareti ile

aralıklarını göstermek için nasıl biçimlendirebilirim? Şu anda y ekseni, sol üstte 0.2, 0.4 ve 1e7 gösteriyor.

from matplotlib import pyplot as plt 
    ... 
    plt.figure(figsize=(8,4)) 
    plt.plot(x_values, y_values) 
    plt.ylabel('Amount') 
    ... 
    plt.savefig(img_path) 
+0

bize arsa gösterin. – Hun

+0

Bu sayfaya bakın: http://matplotlib.org/examples/pylab_examples/custom_ticker1.html –

+0

"Matlab" etiketli soru niçin? – kazemakase

cevap

0

Matlab Örnek Sep1000Str() olduğunu

% Years on x axis 
x = 2010:2016; 

% Dollar amount on y axis 
y = linspace(4000000,8000000,length(x)); 

% Plot and save the tick values that Matlab generates 
plot(x,y); 
yTicks = get(gca,'YTick'); 

% Turn ticks into non-exponential values 
a = textscan(num2str(yTicks),'%f'); 

% Format into strings representing dollar amount with delimiter etc. 
newYTickLabels = Sep1000Str(a{1}); 

% Set your new ticklabels 
set(gca,'YTickLabel',newYTickLabels) 

:

function output = Sep1000Str(a) 
n = length(a); 
for k = 1:n 
    S = sprintf('$%.2f', a(k)); 
    S(2, length(S) - 6:-3:2) = ','; 
    S = {transpose(S(S ~= char(0)))}; 
    output(k) = S; 
end 
+0

python'da mı? – user1187968

+1

Sanırım Matlab'da, –

+0

'dan bahsettiğim gibi, umarım bu sizin probleminizi çözer, @ user1187968. Eğer öyleyse, lütfen cevap verin ve cevabı kabul edin. Başka bir şeye ihtiyacın olursa haberim olsun. – JCKaz

İlgili konular