2016-08-19 42 views
-1

私は神経回路を描くためにmatplotlibを使用しています。私は神経網を描くコードを見つけましたが、上から下に向いています。私は左から右に方向を変更したいと思います。ですから、基本的にすべての図形をプロットした後、x軸とy軸を変更したいと思います。これを行う簡単な方法はありますか? また、パラメータの「方向」を水平方向(下のコード)に変更できるとの回答が見つかりましたが、実際にはどこにコードをコピーする必要があるのか​​分かりません。それは私に同じ結果を与えるだろうか?matplotlibのx軸とy軸を変更するにはどうすればよいですか?

matplotlib.pyplot.hist(x, 
        bins=10, 
        range=None, 
        normed=False, 
        weights=None, 
        cumulative=False, 
        bottom=None, 
        histtype=u'bar', 
        align=u'mid', 
        orientation=u'vertical', 
        rwidth=None, 
        log=False, 
        color=None, 
        label=None, 
        stacked=False, 
        hold=None, 
        **kwargs) 

答えて

1

あなたのコードには、matplotlibでヒストグラムを起動する方法の例があります。 Pyplotのデフォルトインターフェイスを使用していることに注意してください(必ずしもあなた自身のFigureを構築する必要はありません)。

ように、この行:

orientation=u'vertical', 

は次のようになります。

orientation=u'horizontal', 

、あなたはバーが左から右に移動する場合。しかしこれはy軸に関してあなたを助けません。このコマンドを使用する必要があり軸yを反転させるには:

plt.gca().invert_yaxis() 

次の例では、あなたがどのように(変更を認識しやすいように、非対称)ランダムなデータからヒストグラムを構築することを示しています。最初のプロットは通常のヒストグラムであり、2番目のプロットはヒストグラムの向きを変更します。最後にy軸を反転させます。

import numpy as np 
import matplotlib.pyplot as plt 

data = np.random.exponential(1, 100) 

# Showing the first plot. 
plt.hist(data, bins=10) 
plt.show() 

# Cleaning the plot (useful if you want to draw new shapes without closing the figure 
# but quite useless for this particular example. I put it here as an example). 
plt.gcf().clear() 

# Showing the plot with horizontal orientation 
plt.hist(data, bins=10, orientation='horizontal') 
plt.show() 

# Cleaning the plot. 
plt.gcf().clear() 

# Showing the third plot with orizontal orientation and inverted y axis. 
plt.hist(data, bins=10, orientation='horizontal') 
plt.gca().invert_yaxis() 
plt.show() 

プロット1についての結果は、(デフォルトのヒストグラム)である:

default histogram in matplotlib

秒(変更のバーの向き):

default histogram in matplotlib with changed orientation

そして最後に第三(反転y軸):

Histogram in matplotlib with horizontal bars and inverted y axis

関連する問題