2016-05-15 5 views
2

私はマットショーのスケールバーを見たいと思っています。私はかなり長い時間を探して答えを見つけられませんでした。それ、どうやったら出来るの?matshowでスケールバーを見るにはどうすればいいですか?

コードは非常に簡単です:私の知る限りscale barはmatplotlibののネイティブ機能の一部ではありません知っているよう

def analyze_results(): 
    l_points = [np.array([10, 9, -1]), np.array([-4, 4, 1]), np.array([-6, 2, -1]), np.array([ 7, -2, 1]), np.array([-3, 2, -1]), np.array([ 3, -5, -1]), np.array([-5, 10, 1]), np.array([-10, 9, -1]), np.array([ 4, -4, 1]), np.array([-4, 7, 1])] 
    num_elemnts = 2 * const_limit + 1 
    loss = np.zeros((num_elemnts, num_elemnts)) 
    for i in range(-const_limit, const_limit + 1): 
     for j in range(-const_limit, const_limit + 1): 
      if ((i == 0) & (j == 0)): 
       continue 
      w = (i, j) 
      loss[i, j] , _ = gradient_hinge_loss(l_points, w) 

    return loss 

if __name__ == '__main__': 
    loss_hinge_debugger = analyze_results() 
    plt.matshow(loss_hinge_debugger) 
    plt.show() 

答えて

3

matplotlib-scalebarを使って考えてみてください。リンクでは、コード例を見つけることができます:

import matplotlib.pyplot as plt 
import matplotlib.cbook as cbook 
from matplotlib_scalebar.scalebar import ScaleBar 
plt.figure() 
image = plt.imread(cbook.get_sample_data('grace_hopper.png')) 
plt.imshow(image) 
scalebar = ScaleBar(0.2) # 1 pixel = 0.2 meter 
plt.gca().add_artist(scalebar) 
plt.show() 

、本になるはずである:

matplotlib scale bar from matplotlib scalebar lib

私はそれを試したことがない(私はlibには、インストールされていることはありません)が、それはピップからインストールするのに十分な簡単なはず:

pip install matplotlib-scalebar 

であなたはcolorbar(間違いを探しています

plt.colorbar() 

、matshow(hereから適応例)と一緒になった:

import matplotlib.pyplot as plt 

def samplemat(dims): 
    """Make a matrix with all zeros and increasing elements on the diagonal""" 
    aa = np.zeros(dims) 
    for i in range(min(dims)): 
     aa[i, i] = i 
    return aa 

# Display 2 matrices of different sizes 
dimlist = [(12, 12), (15, 35)] 
#for d in dimlist: 
plt.matshow(samplemat(dimlist[0])) 
plt.colorbar() 

plt.show() 
は、このことになる。■あなたがこれを使用することができます)起こるのか

matshow with colorbar

+0

これは10倍です –

関連する問題