2017-07-07 10 views
-1
import numpy as np 
C=np.random.rand (500) 
S=np.random.rand(500) 
def function(s,c): 
    return s*2+c 
dc=[] 
for i in range(len(C)): 
    dc.append(function(S[i],C[i]) 

ランダムな結果をimshowでimshowする方法がわかりません。 - np.reshapeを使用して2d -arrayにimshowメソッドを使用して2次元ランダムデータをプロットする方法

+0

'S'と' C'は1次元配列です - imshowでプロットすることができる行列を得るにはどうすればよいでしょうか? –

+0

'dc.append'コマンドに閉じ括弧がありません –

+0

はい、2次元配列に変換してimshowまたはpcolorしたいのですが、SとCを順番に変更してdcがなくなるとします。 –

答えて

1

あなたは1dを変換することができます:私はこのような画像を取得したいです。また、配列演算を要素ごとに行う必要はありません - numpyこれはあなたのためです。以下のコードは、うまくいけば(それはあなたの質問からかなり明確ではありません)あなたが欲しいものを行います。

import numpy as np 
from matplotlib import pyplot as plt 


C=np.random.rand(500).reshape((20,25)) 
S=np.random.rand(500).reshape((20,25)) 

def function(s,c): 
    return s*2+c 

dc = function(S,C) 

plt.imshow(dc) 
plt.show() 

結果は次のようになります。テストで

result of the given code

+0

はい、それは2Dを目的の配列に変換する良いieadです。私はそれを得る::)ありがとう –

0

、私は散布マップを取得し、すべてのことを示すのは良いことではありません。

import numpy as np 
import matplotlib.pyplot as plt 
def function(C,S): 
    return 2*C+S**2 
axis=plt.subplot() 
Sand=np.random.rand(50) 
Clay=np.random.rand(50) 
dc=function(C=Clay,S=Sand) 
plt.scatter(Clay,Sand,c=dc,cmap='jet') 
axis.set_xlabel('Clay') 
axis.set_ylabel('Sand') 

enter image description here

だから私は、他の方法.Pcolorまたは関数imshowでそれを表示したいit.So Iを実現するための良い方法です:

import numpy as np 
from matplotlib.figure import Figure 
import matplotlib.pyplot as plt 
axis=plt.subplot() 
def function (C,S): 
    return 2*C+S**2 
axis=plt.subplot() 
dc=np.ones(50*50).reshape(50,50) 
Sand=np.random.rand(50) 
Clay=np.random.rand(50) 
Clay_or=sorted(Clay) 
Sand_or=sorted(Sand,reverse=True) 
for i in range(50): 
    for j in range (50): 
     result=function(Clay_or[i],Sand_or[j]) 
     dc[j][i]=result 
plt.imshow(dc,cmap='jet',extent=(0,1,0,1)) 
axis.set_xlabel('Clay') 
axis.set_ylabel('Sand') 

enter image description here

結果は私は、pcolor関数を使用する場合、軸のダニを設定する方法、質問がありますか?

関連する問題