2017-01-22 7 views
1

CとMatlabからPythonを初めて使用しています。私は、洪水頻度解析のログ確率(log yaxis-probability xaxis)プロットを生成するスクリプトを作成しています。私は、x軸の確率スケーリングのため、次のStackOverflowのソリューションを使用しています:カスタムxaxis確率スケールでyaxisラベルが表示されないpython

Creating Probability/Frequency Axis Grid (Irregularly Spaced) with Matplotlib

このソリューションは、x軸のための素晴らしい作品。しかし、私がy10をlog10としてスケールすると、yaxisのラベルは消えます。プロットの作成に使用されるコードは次のとおりです。
Here is what the resulting figure looks like - note the lack of yaxis ticks or tick labels:

: - y軸目盛りの不足に注意したり、ラベルをチェック

ここ
# Step 1: load the needed pacakages 
import numpy as np 
import matplotlib.pyplot as plt 
from numpy import ma 
from matplotlib import scale as mscale 
from matplotlib import transforms as mtransforms 
from scipy.optimize import curve_fit 

# Step 2: Load up some files and specify variables 
# I have not included this part of the code b/c it works fine 

# Step 3: Execute the xaxis proability scaling code referenced above 

# Step 4: Create a figure 
fig = plt.figure(1) 
# Call the firts subplot 
ax = fig.add_subplot(2,1,1) 
# Create the first subplot 
scatter, = ax.plot(NE,Floods,'mo') 
# Grab the axes 
ax = plt.gca()  
# Set the axis lables 
ax.set_ylabel('Discharge in CMS') 
ax.set_xlabel('Non-exceedance Probability') 

#Adjust the yaxis format 
ax.set_yscale('log')  
ax.set_ylim((0.01, 1000)) 
plt.tick_params(axis='y', which='major')  
ax.yaxis.set_major_locator(FixedLocator([0.1,1,10,100,1000])) 

# Specify the xaxis tick labels  
points = np.array([0.1,1,2,5,10,20,30,40,50,60,70,80,90,95,99,99.9])  

# Set the x-axis scale, labels and format 
ax.set_xscale('probability', points = points, vmin = .01) 
xlabels=points 
ha = ['right', 'center', 'left'] 
ax.set_xticklabels(xlabels, rotation=-90, ha=ha[1]) 

# Specify no grid  
plt.grid(False) 
# Show the plot 
plt.show() 

が得られた数値がどのように見えるかです:「確率」のコールは、上記のStackOverflowのソリューションを使用してスケーリング確率軸を指し、

ご提供いただけるお手伝いがあれば幸いです。ありがとう。

+0

実行中のスクリプトを提供してください: 'NameError:name 'NE' not defined'。 –

+0

質問をする前に、[ツアーに参加する](http://stackoverflow.com/tour)をご覧ください。そこに[MCVE]を作ることが重要であることがわかります。あなたが残した部分は確かにあなたのためにうまくいっていますが、他の人があなたの例を確認するのを妨げます。経験豊富なユーザーにとっては、コードを実行するためにデータを生成するのに最大10分かかることがありますが、ソリューションを提供するには通常1分もかかりません。ここで問題はFixedLocatorです。 [この質問](http://stackoverflow.com/questions/14530113/set-ticks-with-logarithmic-scale)可能な代替案。 – ImportanceOfBeingErnest

+0

私はコード全体を投稿するために私の質問を編集しようとしていますが、質問を編集することができません....私はStackoverflowに新しいです。 – SurfProc

答えて

1

ImportanceOfBeingErnestに感謝します。

set ticks with logarithmic scale

コード変更がFixedLocator呼び出しを置き換えることだった、とyticksの設定を呼び出して、それ以上のコール、およびフォーマッタ:私が提案したリンクで実行可能な解決策を見つけました。ここで、オリジナルと修正されたコード

元のコードである:ここで

#Adjust the yaxis format 
ax.set_yscale('log')  
ax.set_ylim((0.01, 1000)) 
plt.tick_params(axis='y', which='major')  
ax.yaxis.set_major_locator(FixedLocator([0.1,1,10,100,1000])) 

は、変更されたコードである:ここで

#Adjust the yaxis format 
ax.set_yscale('log')  
ax.set_ylim((0.01, 1000)) 
ax.set_xticklabels(["0.01", "0.1", "1", "10", "100", "1000"]) 
ax.get_xaxis().set_major_formatter(plt.ticker.ScalarFormatter()) 

は、変更されたコードを有する得られた図である。

plot with correct yaxis

質問が回答されました。再度、感謝します。

関連する問題