2017-07-31 3 views
0

いくつかのプログラムを実行している4つのツールのパフォーマンスを分析したいと思います.1つのサブプロットは、すべてのプログラムの1つのツールの結果です。私は、次のようにプログラムリストとプロット一部を毎回反復するforループを使用 enter image description herePython:サブプロット内のバーにx tickを特に設定しますか?

:結果は次のようになります。

enter image description here

しかし、プロットは、単一のもののように見えると私axis.set_xticks()を使用してxティックを区切ることはできません。この機能は効果がないようです。

x tickを設定するのに正しい関数を使用しますか?あるいは、私はこのプロットをどうすればいいですか?

draw_hist_query()

データサンプル私の質問のための最も重要な関数であってもよい:

boolector,ppbv,stp,z3 
0.05349588394165039,0.015434503555297852,0.028127193450927734,0.11303281784057617 
0.0027561187744140625,0.004331827163696289,0.007134914398193359,0.016040563583374023 
0.003190755844116211,0.005587577819824219,0.002897500991821289,0.013916015625 
0.009758472442626953,0.02006363868713379,0.0031282901763916016,0.011539697647094727 
0.057138681411743164,0.012826681137084961,0.030836820602416992,0.0217435359954834 

コード:

あなたはいくつかのオプションを持っている一般的に
index = range(len(solvers)) 
fig, axes = plt.subplots(nrows=4) 
solvers = ['z3', 'stp', 'boolector', 'ppbv'] 
colors = ['g', 'c', 'b', 'r', 'y', 'orange', 'grey'] 
ticks = [0.1, 0.5, 1.0, 2.0] 
width=0.2 

# program entry 
def all_time_query(path): 
    csv = xxx.csv # the array of data to be analyzed, one csv for one program 
    for axis in axes: 
     axis.set_xticks(range(len(csv))) 
    for c in csv: 
     multi_time_query(c) # draw the bar pair for c, which shows the upper image for one program on four tools 


def multi_time_query(csv): 
    data = pd.read_csv(csv) 
    for solver in solvers: # the four tools 
     bin = index[solvers.index(solver)] 
     hist_t_query(data, solver, ax=axes[bin]) # details to draw the bar pair, uses dataframe.plot.bar 



def hist_t_query(data, solver, ax): 
    solver_data = pd.DataFrame(data).as_matrix(columns=[solver]) 
    # draw one bar for demo 
    draw_hist_query(pd.DataFrame(solver_data), ax) 


# left of bar pair, the right one is similar 
def draw_hist_query(df, ax): 
    count = [] 
    for i in range(len(ticks)): 
     count.append(df[df < ticks[i]].count()) 
     color = stat.colors[i] 
     if i == 0: 
      count[i].plot.bar(ax=ax, color=color, width=width, position=0) 
     else: 
      (count[i] - count[i - 1]).plot.bar(bottom=count[i - 1], 
               ax=ax, color=color, width=width, position=0) 
+1

あなたには、いくつかのコードを追加することができます。ここでは

はコードの私の新しいバージョンですか?サブプロットを使用していますか?もしそうなら、subplots_adjustでそれらを調整することができますhttp://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.subplots_adjust –

+0

@ KacperWolkowskiはいくつかのコードを追加しました –

+0

私はあなたも 'hist_t_query'を表示する必要があると思います特に 'dataframe.plot.bar'と呼ばれる部分)、そうでなければ何が起こっているのかを知ることは困難です。 –

答えて

0

は最後に、私はこの問題を解決: enter image description here

私はサブプロットについての前で誤って考えたもの。私はもう一つのペアがすでに存在してから、サブプロットに別のバーのペアを追加したかったのです。 ただし、1つのサブプロットは一緒に(一度に)プロットする必要があり、分離しないでください。私の場合、1つのサブプロットのバーが一緒に表示され、すべてのサブプロットをプロットするのに4回だけ必要です。

def time_query_project(path): 
    fig, axis = plt.subplots(nrows=4) 
    csv = sio.find_csv(path) 
    data = {} 

    for solver in solvers: 
     for c in csv: 
      df = pd.DataFrame(pd.read_csv(c), columns=[solver]) 
      data.update({get_name(c): df.to_dict()[solver]}) 
     df = pd.DataFrame.from_dict(data, orient='columns') 
     ax = axis[solvers.index(solver)] 
     ax.set_ylabel(solver) 
     hist_t_query(df, ax) 


def hist_t_query(data, solver, ax): 
    solver_data = pd.DataFrame(data).as_matrix(columns=[solver]) 
    # draw one bar for demo 
    draw_hist_query(pd.DataFrame(solver_data), ax) 


# left of bar pair, the right one is similar 
def draw_hist_query(df, ax): 
    count = [] 
    for i in range(len(ticks)): 
     count.append(df[df < ticks[i]].count()) 
     color = stat.colors[i] 
     if i == 0: 
      count[i].plot.bar(ax=ax, color=color, width=width, position=0) 
     else: 
      (count[i] - count[i - 1]).plot.bar(bottom=count[i - 1], 
               ax=ax, color=color, width=width, position=0) 
0

plt.tight_layout()を使用すると自動的にすべてが行われるか、plt.subplot_adjust()を使用して各パラメータを自分で指定することができます。 あなたがドキュメントで見ることができるように、署名はそのようなものです:

subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) 

ともあなたは対話型のウィンドウに移動する場合は、あなたがそこにパラメータを調整するためのオプションを持っている、とあなたはあなたのグラフがする方法を見ることができます各パラメータ

enter image description here

に変更してから、あなたはあなたのために最善であるものは何でもしてsubplot_adjustを呼び出すことができます。

私はそれが役に立ちそうです。

+0

実際、私の問題は**サブプロット**です。私はこれを自分で解決しました。興味があれば私の答えを見てください。ありがとう、すべて同じ:) –

関連する問題