私は、同じ極座標プロット上に円形のヒストグラムとベクトル(重ねる)の両方をプロットしようとしていますが、表示するベクトルを得ることはできません。Python/Matplotlib - 循環ヒストグラムの上にベクトルの合計をプロットするにはどうすればよいですか?
基本的に私のデータセットは、繰り返しサイクル中に単一イベントが発生する時間から成ります。このデータは、配列all_phasesにあります。これは、これらの各イベントの度数のリストです。 (1)循環ヒストグラム(度数範囲に対応するビン)と(2)これらの値すべてのコヒーレンスの尺度としてのベクトル和(各事象を単位ベクトルとして扱うこと)を示したい)。
"histo"と名付けられたサブプロット上にこれらのものを個別にプロットすることができますが、両方をプロットしようとするとヒストグラムのみが表示されます。私は、両方のオブジェクトのz-インデックスを使用しないで再生しようとしました。コードは次のとおりです。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import math
array = np.array
all_phases = [array([-38.24240218]), array([-120.51570738]), array([-23.70224663]),
array([114.9540152]), array([ 2.94523445]), array([-2.16112692]), array([-18.72274284]),
array([13.2292216]), array([-95.5659992]), array([15.69046269]), array([ 51.12022047]),
array([-89.10567276]), array([ 41.77283949]), array([-9.92584921]), array([-7.59680678]),
array([166.71824996]), array([-178.94642752]), array([-23.75819463]), array([38.69481261]),
array([-52.26651244]), array([-57.40976514]), array([33.68226762]), array([-122.1818295]),
array([ 10.17007425]), array([-38.03726335]),array([44.9504975]), array([ 134.63972923]),
array([ 63.02516932]),array([-106.54049292]), array([-25.6527599])]
number_bins = 60
bin_size = 360/number_bins
cluster_num = 1
counts, theta = np.histogram(all_phases, np.arange(-180, 180 + bin_size, bin_size), density=True)
theta = theta[:-1]+ bin_size/2.
theta = theta * np.pi/180
a_deg = map(lambda x: np.ndarray.item(x), all_phases)
a_rad = map(lambda x: math.radians(x), a_deg)
a_cos = map(lambda x: math.cos(x), a_rad)
a_sin = map(lambda x: math.sin(x), a_rad)
uv_x = sum(a_cos)/len(a_cos)
uv_y = sum(a_sin)/len(a_sin)
uv_radius = np.sqrt((uv_x*uv_x) + (uv_y*uv_y))
uv_phase = np.angle(complex(uv_x, uv_y))
"""
plot histogram and vector sum
"""
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.16, 0.05, 0.56])
histo = fig.add_subplot(111, polar=True)
histo.yaxis.set_ticks(())
histo.arrow(0,0,0.11, 1, head_width=.01, zorder=2)
plt.suptitle("Phase distribution for Neuron #" + str(cluster_num), fontsize=15, y=.94)
plt.subplots_adjust(bottom=0.12, right=0.95, top=0.78, wspace=0.4)
width = (2*np.pi)/number_bins
bars = histo.bar(theta, counts, width = width, bottom=0.002)
for r, bar in zip(counts, bars):
bar.set_facecolor(plt.cm.jet(r/max(counts)))
bar.set_alpha(0.7)
bar.set_zorder(1)
norm = matplotlib.colors.Normalize(vmin (counts.min())*len(all_phases)*bin_size, vmax=(counts.max())*len(all_phases)*bin_size)
cb1 = matplotlib.colorbar.ColorbarBase(ax1, cmap=plt.cm.jet,
orientation='vertical', norm=norm, alpha=0.4,
ticks=np.arange(0, (counts.max())*len(all_phases)*bin_size)+1,)
cb1.ax.tick_params(labelsize=9)
cb1.solids.set_rasterized(True)
cb1.set_label("# spikes")
cb1.ax.yaxis.set_label_position('left')
plt.show()
cluster_num = cluster_num + 1
vs_radiusとvs_phaseは私が/ histo.arrow(W呼び出す終わる極座標プロット)に入れたいベクトル和の矢印のパラメータです。
私は、それがサブプロットオブジェクトに2つのものを置くことと関係している可能性があると考えていますか?
ご意見やご感想をお寄せください。
から
(0,0)
からあなたの矢印を描くしようとしたがてはならない、と言うことです。最小の例がなければ、問題を特定するのは本当に難しいです。 – ImportanceOfBeingErnestこんにちは - これで修正されました!灰色のセクションをコピーして実行し、実行し、私が見ているものを見ることができるはずです。念押し有難う。 – Jesse
@このコードを実行するとエラーが表示されますか?私は確かにそうです。 –