pythonを用いて、グラフの複数表示をしようとしているのですがうまくいきません。
現状問題としては、表示したいグラフは表示されるが、Figure1に全てのデータが入っているようです。
文字列で表すと以下の様になります。
表示の理想
Figure1 Figure2
1a 3a 1b 3b
2a 4a 2b 4b
のような形で複数のFigureの中にそれぞれ複数のグラフを内包するような形での表示をしたいです。
今の状態だと、最初にFigure1が表示され、そのウィンドウを消すと新たにFigure1が生成されます。
ここ最初に生成されたFigure1のほうには、1a~4aのグラフが内包されていて、
後から生成されたFigure1のほうには、1b~4bのグラフが内包されています。
今後のデータ処理の関係上、Figure1からFigure4を生成出来る様になれば良いのですが…。
以下に表示部分に関するソースを提示します。
分かりにくいかと思いますが宜しくお願いします。
python
1#ウェーブレット解析結果の可視化 2plt.close("all") 3plt.ioff() 4figprops = dict(figsize=(11, 8), dpi=72) 5fig = plt.figure(**figprops) 6 7ax1 = plt.axes([0.1, 0.75, 0.65, 0.2]) 8ax1.plot(t1, iwave, "-", linewidth=1, color=[0.5, 0.5, 0.5]) 9ax1.plot(t1, dat1, "k", linewidth=1.5) 10ax1.set_title("a) {}".format(title)) 11ax1.set_ylabel(r"{}".format(label)) 12 13bx1 = plt.axes([0.1, 0.37, 0.65, 0.28], sharex=ax1) 14levels = [0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32] 15bx1.contourf(t1, np.log2(period), np.log2(power), np.log2(levels), extend="both", cmap=plt.cm.viridis) 16extent = [t1.min(), t1.max(), 0, max(period)] 17bx1.contour(t1, np.log2(period), sig95, [-99, 1], colors="k", linewidths=2, extent=extent) 18bx1.fill(np.concatenate([t1, t1[-1:] + dt, t1[-1:] + dt, 19 t1[:1] - dt, t1[:1] - dt]), 20 np.concatenate([np.log2(coi), [1e-9], np.log2(period[-1:]), 21 np.log2(period[-1:]), [1e-9]]), 22 "k", alpha=0.3, hatch="x") 23bx1.set_title("b){} Wavelet Power Spectrum ({})".format(label, mother.name)) 24bx1.set_ylabel("Period") 25 26Yticks = 2 ** np.arange(np.ceil(np.log2(period.min())), np.ceil(period.max())) 27bx1.set_yticks(np.log2(Yticks)) 28bx1.set_yticklabels(Yticks) 29 30cx1 = plt.axes([0.77, 0.37, 0.2, 0.28], sharey=bx1) 31cx1.plot(glbl_signif, np.log2(period), "k--") 32cx1.plot(var * fft_theor, np.log2(period), "--", color="#cccccc") 33cx1.plot(var * fft_power, np.log2(1./fftfreqs), "-", color="#cccccc", linewidth=1.) 34cx1.plot(var * glbl_power, np.log2(period), "k-", linewidth=1.5) 35cx1.set_title("c) Global Wavelet Spectrum") 36cx1.set_xlabel(r"Power {}^2".format(units)) 37cx1.set_xlim([0, glbl_power.max() + var]) 38cx1.set_ylim(np.log2([period.min(), period.max()])) 39cx1.set_yticks(np.log2(Yticks)) 40cx1.set_yticklabels(Yticks) 41plt.setp(cx1.get_yticklabels(), visible=False) 42 43#---------------------------------------------------------------------- 44dx1 = plt.axes([0.1, 0.07, 0.65, 0.2], sharex=ax1)#グラフの配置指定、 45dx1.axhline(scale_avg_signif, color="k", linestyle="--", linewidth=1.)#xに対する平行な線、出力内容は不明… 46dx1.plot(t1, scale_avg, "k-", linewidth=1.5)#ここのプロット結果を行列?か何かで出力したい 47#---------------------------------------------------------------------- 48 49dx1.set_title("d) {}--{} EMG[V] power spectrum".format(t0, max(t1))) 50dx1.set_xlabel("Time [{}]".format(timetable)) 51dx1.set_ylabel(r"Scale Avg") 52ax1.set_xlim([t1.min(), t1.max()]) 53 54plt.show() 55 56#ウェーブレット解析結果の可視化2 57plt.close("all") 58plt.ioff() 59figprops = dict(figsize=(11, 8), dpi=72) 60fig = plt.figure(**figprops) 61 62ax2 = plt.axes([0.1, 0.75, 0.65, 0.2]) 63ax2.plot(t2, iwave, "-", linewidth=1, color=[0.5, 0.5, 0.5]) 64ax2.plot(t2, dat2, "k", linewidth=1.5) 65ax2.set_title("a) {}".format(title)) 66ax2.set_ylabel(r"{}".format(label)) 67 68bx2 = plt.axes([0.1, 0.37, 0.65, 0.28], sharex=ax2) 69levels = [0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32] 70bx2.contourf(t2, np.log2(period2), np.log2(power2), np.log2(levels), extend="both", cmap=plt.cm.viridis) 71extent = [t2.min(), t2.max(), 0, max(period2)] 72bx2.contour(t2, np.log2(period2), sig95_2, [-99, 1], colors="k", linewidths=2, extent=extent) 73bx2.fill(np.concatenate([t2, t2[-1:] + dt, t2[-1:] + dt, 74 t2[:1] - dt, t2[:1] - dt]), 75 np.concatenate([np.log2(coi), [1e-9], np.log2(period2[-1:]), 76 np.log2(period2[-1:]), [1e-9]]), 77 "k", alpha=0.3, hatch="x") 78bx2.set_title("b){} Wavelet Power Spectrum ({})".format(label, mother.name)) 79bx2.set_ylabel("Period") 80 81Yticks = 2 ** np.arange(np.ceil(np.log2(period2.min())), np.ceil(period2.max())) 82bx2.set_yticks(np.log2(Yticks)) 83bx2.set_yticklabels(Yticks) 84 85cx2 = plt.axes([0.77, 0.37, 0.2, 0.28], sharey=bx2) 86cx2.plot(glbl_signif2, np.log2(period2), "k--") 87cx2.plot(var2 * fft_theor, np.log2(period2), "--", color="#cccccc") 88cx2.plot(var2 * fft_power2, np.log2(1./fftfreqs), "-", color="#cccccc", linewidth=1.) 89cx2.plot(var2 * glbl_power2, np.log2(period2), "k-", linewidth=1.5) 90cx2.set_title("c) Global Wavelet Spectrum") 91cx2.set_xlabel(r"Power {}^2".format(units)) 92cx2.set_xlim([0, glbl_power2.max() + var2]) 93cx2.set_ylim(np.log2([period2.min(), period2.max()])) 94cx2.set_yticks(np.log2(Yticks)) 95cx2.set_yticklabels(Yticks) 96plt.setp(cx2.get_yticklabels(), visible=False) 97 98#---------------------------------------------------------------------- 99dx2 = plt.axes([0.1, 0.07, 0.65, 0.2], sharex=ax2) 100dx2.axhline(scale_avg_signif2, color="k", linestyle="--", linewidth=1.) 101dx2.plot(t2, scale_avg2, "k-", linewidth=1.5) 102#---------------------------------------------------------------------- 103 104dx2.set_title("d) {}--{} EMG[V] power spectrum".format(t0, max(t2))) 105dx2.set_xlabel("Time [{}]".format(timetable)) 106dx2.set_ylabel(r"Scale Avg") 107ax2.set_xlim([t2.min(), t2.max()]) 108 109plt.show() 110

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/05 08:39
2019/01/05 08:58
2019/01/05 09:07
2019/01/05 09:14 編集
2019/01/05 09:20