この答えはmatplotlibのを使用しています。
最初の質問に答えるには、ポイントに注釈を付けるためにデータが所与の座標にポイントを生成する頻度を調べる必要があります。すべての値が整数の場合、2次元ヒストグラムを使用して簡単に行うことができます。 hstogramのうち一つは、その後カウント値がゼロでないものだけビンを選択することになると、ループ内でそれぞれの値に注釈を付ける:
x = [3, 0, 1, 2, 2, 0, 1, 3, 3, 3, 4, 1, 4, 3, 0]
y = [1, 0, 4, 3, 2, 1, 4, 0, 3, 0, 4, 2, 3, 3, 1]
import matplotlib.pyplot as plt
import numpy as np
x = np.array(x)
y = np.array(y)
hist, xbins,ybins = np.histogram2d(y,x, bins=range(6))
X,Y = np.meshgrid(xbins[:-1], ybins[:-1])
X = X[hist != 0]; Y = Y[hist != 0]
Z = hist[hist != 0]
fig, ax = plt.subplots()
ax.scatter(x,y, s=49, alpha=0.4)
for i in range(len(Z)):
ax.annotate(str(int(Z[i])), xy=(X[i],Y[i]), xytext=(4,0),
textcoords="offset points")
plt.show()
あなたは、すべての点が、結果をプロットしないことを決定することができます散布点の色やサイズを変更する機会を提供していますヒストグラムから、
ax.scatter(X,Y, s=(Z*20)**1.4, c = Z/Z.max(), cmap="winter_r", alpha=0.4)
すべての値が整数であるので10
、あなたもoccurancesの数を計算するためにnecesityがなければ、イメージプロットのため
fig, ax = plt.subplots()
ax.imshow(hist, cmap="PuRd")
for i in range(len(Z)):
ax.annotate(str(int(Z[i])), xy=(X[i],Y[i]), xytext=(0,0), color="w",
ha="center", va="center", textcoords="offset points")
を選ぶことができ、別のオプションは、hexbinプロットを使用することです。これは、六角形のビンニングのために、ドットの位置が少し不正確になりますが、私はまだこのオプションについて言及したがっています。私はこのために申し訳ありません@ImportanceOfBeingErnest
import matplotlib.pyplot as plt
import matplotlib.colors
import numpy as np
x = np.array(x)
y = np.array(y)
fig, ax = plt.subplots()
cmap = plt.cm.PuRd
cmaplist = [cmap(i) for i in range(cmap.N)]
cmaplist[0] = (1.0,1.0,1.0,1.0)
cmap = matplotlib.colors.LinearSegmentedColormap.from_list('mcm',cmaplist, cmap.N)
ax.hexbin(x,y, gridsize=20, cmap=cmap, linewidth=0)
plt.show()
。私はそれがよりよく見えることを望む! (私の貧しい英語のためかもしれません!) – renakre
matplotlibには、あなたが望むことを自動的に行う方法はありません。 (私は陽気なことは知らないが)。おそらくnumpy histogram2dまたはpandasピボットテーブルを使用して、どの点が重なっているかを調べる必要があるかもしれません。次に、ポイントに注釈を付けることができます(たとえば、matplotlib.textを使用して)。 – ImportanceOfBeingErnest
@ImportanceOfBeingErnest異なるプロットを使用してデータを表現するための推奨はありますか? – renakre