2017-09-07 8 views
0

コンテキストPythonの:無効な引数RGBA 0.0カラーポイントは、クラス

によると、私はいくつかの点

points = np.random.uniform(0,10, size = (10,2)) 
# array([[ 7.35906037, 6.50049804], 
     [ 3.21883403, 3.81452312], 
     [ 3.52107154, 1.68233797], 
     [ 1.47699577, 6.01692348], 
     [ 3.76051589, 0.25213394], 
     [ 8.93701081, 5.20377479], 
     [ 6.5347188 , 2.12940006], 
     [ 3.62550069, 5.80619507], 
     [ 1.33393325, 5.0088937 ], 
     [ 6.99034593, 7.40277623]]) 

を持っていると、彼らは "分類" または標識されています。これは私がリスト pointsの各点のラベル(順番に)を表し

labels = np.random.randint(0,3, size = 10) 
    # array([2, 0, 1, 2, 2, 1, 1, 0, 1, 2]) 

を有することを意味します。

私はまた、いくつかの余分なポイントに

extraPoints = np.random.uniform(0,10, size = (3,2)) 
# array([[ 1.91211141, 3.71208978], 
# [ 8.10463536, 1.88948511], 
# [ 9.79796593, 3.39432552]]) 

を持っている基本的にはこれらの点のそれぞれは、クラスラベルを決定します。どのようにラベルを決定したかは問題ではありません。しかし、あなたが知っておかなければならないのは、これらの余分なポイントのそれぞれが1つの唯一のラベルに関連付けられていることです。したがって、余分なポイントとラベルの可能性は同じです。私は散布図をやりたい

問題

。私はextraPointsの各ポイントに異なる色を割り当てたいので、この色は各クラスに対応しています。これは、基本的にextraPoints[0]がクラス0に関連付けられ、extraPoints[1]がクラス1に関連付けられ、extraPoints[2]がクラス2に関連付けられることを意味します。

また、pointsに点を散布したいと思います。 pointsの各ポイントは、対応するラベルlabelsに関連付けられていることに注意してください。 たとえば、[ 7.35906037, 6.50049804]は、クラス2にあり、したがって、同色のextraPoints[2] = [ 9.79796593, 3.39432552]です。同様にpointsのポイント[ 3.21883403, 3.81452312]labelsにクラス0に関連付けられているので、しかし、私は本当にどのように理解していない

私はplt.scatter()c引数を使用してみました試みるextraPoints[0] = [ 1.91211141, 3.71208978]

私の同じ色を持っています"無効なRGBA引数0.0"と表示されることもありますが、それは任意です。

pointsextraPointsを区別するために、私はextraPointsをより大きく透明にするつもりです。

import matplotlib.pyplot as plt 
# I scatter the points, and assign c to labels. So hopefully each 
# point that ends up in the same label will have the same 
# color? I think this part is fine, although I am not sure 
plt.scatter(points[:,0], points[:,1], c = labels) 
plt.scatter(extraPoints[:,0], extraPoints[:,1], s = 100, alpha = 0.3, c = np.arange(len(extraPoints))) 

あなたは別の実行のために、あなた自身のために試してみてください(毎回ので、我々は、ランダムな配列を持っている)我々は正しい(あるいはほとんど)それを得る可能性がありますいずれか、またはタイトルのエラーを取得することができたよう。なぜこれが起こるのですか?このような状況を考えるとブレーブス

-for

エクストラ、私はラベルやextraPointsの種類(すなわち3を持っているとして、私はまた、いくつかの値

values = np.random.uniform(0,50, size = 3) 
# array([ 14.63459424, 37.41573654, 34.45202082]) 

は、私は同じ数の値を持っていたと想像この場合)。現在、これらはそれぞれ対応するextraPointに関連付けられています。したがって、最初のextraPointなどの最初の値。

私は上記のプロットを実行したいと思いますが、色は小さな値の場合はより明るく、大きい値の場合は暗い色のグラデーションになります(またはその反対)。どうやってやるの?私はカラーマップについて読みましたが、私はそれを自分の問題と完全に統合できません。

上記の値について例えば、我々は得る: scatter

をあなたが見ることができるように、私は色を制御することはできません。それだけでなく、クラスにどのポイントが含まれているのか分かりません(戻って手動で各ポイントを見ない限り、明らかに私はこれを望んでいません)。これが(そして私がここでカバーしない他の理由)なぜvaluesの値に基づいて色付けしたいのかという理由です。私は「最強」であるクラスを知っているように、具体的には、私は、私の点の色を導くことができる値[10, 20 30]の範囲を持っている、と言う希望

答えて

1

まず問題:コードはnp.random.uniform(0,10, size = 3)以来、実行されません。 1D配列を返しますが、後で2D(extraPoints[:,0])と予想します。

第二の問題labels 1及び3一意のエントリとの間有することができ、したがってnp.unique(labels) 3に長さ1のものとすることができるあなたが色より多くのポイントを有するように(例えばlabelsは、np.unique(labels) == [0]ことがすべてゼロであってもよいです)。しかし、cは、単一の色引数または入力座標と同じ長さの値のリストのいずれかを求めます。

第3の問題:長さ3または4のリストまたは配列を指定すると、単一のRGBまたはRGBAカラーまたはカラーマップの値のリストであるかどうかは不明です。あなたが実際にこの問題に遭遇したかどうかは、あなたが最初と2番目の問題を解決するまで、確かに言うことができません。

更新:最初の2つの問題が解決された後、おそらくカラーバーと便利なカラーマップを探しているだけです。

enter image description here

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.colors 

points = np.random.uniform(0,10, size = (10,2)) 

labels = np.random.randint(0,3, size = 10) 

extraPoints = np.random.uniform(0,10, size = (3,2)) 

sc = plt.scatter(points[:,0], points[:,1], c = labels) 
sc2 = plt.scatter(extraPoints[:,0], extraPoints[:,1], s = 144, alpha = 0.7, 
      c = np.arange(len(extraPoints))) 

plt.colorbar(sc) 

plt.show() 
それとも、あなたは個々の色を持つようにしたい場合は:ImportanceOfBeingErnestへ

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.colors 

points = np.random.uniform(0,10, size = (10,2)) 

labels = np.random.randint(0,3, size = 10) 

extraPoints = np.random.uniform(0,10, size = (3,2)) 

colors=["red", "gold", "limegreen"] 
cmap = matplotlib.colors.ListedColormap(colors) 

sc = plt.scatter(points[:,0], points[:,1], c = labels, cmap=cmap, vmin=-0.5,vmax=2.5) 
sc2 = plt.scatter(extraPoints[:,0], extraPoints[:,1], s = 144, alpha = 0.7, 
      c = np.arange(len(extraPoints)), cmap=cmap, vmin=-0.5,vmax=2.5) 

plt.colorbar(sc, ticks=np.arange(len(extraPoints))) 

plt.show() 

enter image description here

+0

最初の問題はタイプミスであり、修正されました。あなたは正しいです、3x2配列でなければなりません –

+0

2番目の問題について私は 'c = np.arange(len(extraPoints)) 'を使用することができます –

+0

こうして2番目の問題を修正すると、色を持つ' extraPoints' 'points'にはその色がありません。それはそれらのケースをカバーします。 –

0

おかげで、私はこの問題を解決するために管理しました。私は私の説明が本当に悪かったけど、ここで私は将来的には同じ問題を見つけるかもしれない誰かのためにそれを投稿:

ImportanceOfBeingErnestソリューション

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.colors 

points = np.random.uniform(0,10, size = (10,2)) 

labels = np.random.randint(0,3, size = 10) 

extraPoints = np.random.uniform(0,10, size = (3,2)) 

colors=["red", "gold", "limegreen"] 
cmap = matplotlib.colors.ListedColormap(colors) 

sc = plt.scatter(points[:,0], points[:,1], c = labels, cmap=cmap, vmin=-0.5,vmax=2.5) 
sc2 = plt.scatter(extraPoints[:,0], extraPoints[:,1], s = 144, alpha = 0.7, 
      c = np.arange(len(extraPoints)), cmap=cmap, vmin=-0.5,vmax=2.5) 

plt.colorbar(sc, ticks=np.arange(len(extraPoints))) 

plt.show() 

マイアドインそれは私が何をしたいん

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.colors 

points = np.random.uniform(0,10, size = (10,2)) 

labels = np.random.randint(0,3, size = 10) 

extraPoints = np.random.uniform(0,10, size = (3,2)) 
# CREATE VALUES 
values = np.random.uniform(0,50, size=3) 

colors=["red", "gold", "limegreen"] 
cmap = matplotlib.colors.ListedColormap(colors) 

sc = plt.scatter(points[:,0], points[:,1], c = np.array([values[j] for j in labels]), cmap=cmap, vmin=-0.5,vmax=2.5) 
sc2 = plt.scatter(extraPoints[:,0], extraPoints[:,1], s = 144, alpha = 0.7, 
      c = values, cmap=cmap, vmin=-0.5,vmax=2.5) 

plt.colorbar(sc, ticks=np.arange(len(extraPoints))) 

plt.show() 

差がscの色は現在のと同じ順序でvaluesの値によって決定されることですlabelsであり、同時にextraPointsの点は、値の強さと次数がvaluesで色付けされています。