Differences between revisions 3 and 4
Revision 3 as of 2020-03-21 13:11:40
Size: 1026
Comment:
Revision 4 as of 2020-04-11 13:22:03
Size: 2205
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:

=== 複数の時系列を縦に並べてplotする ===
[[https://gwpy.github.io/docs/stable/timeseries/plot.html#plotting-multiple-timeseries-together|ここ]]に書いてある、gwpy.plotのPlot()がオススメ。<<BR>>
注意点は、TimeSeriesのlistやTimeSeriesDictを引数にしてまとめて渡した場合は ''separate=True'' をしても分割されないという謎仕様。面倒だが1つ1つ手で並べる必要がある。

{{{#!python
from gwpy.plot import Plot
plot = Plot(l1hoft, h1hoft)
plot = Plot(l1hoft, h1hoft, separate=True, sharex=True)
plot.show()
}}}
{{https://gwpy.github.io/docs/stable/_images/plot-7.png}}

戻り値 (ここでは ''plot'')は、[[https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.figure.html|matplotlibのfigure]]だと思ってしまってよい。<<BR>>
なので、それぞれのy軸ラベルや全体のタイトルを付けるには以下のようにする。
{{{#!python
import matplotlib.pyplot as plt
axes = plot.get_axes()
ylabel = ['y1','y2']
for i, ax in enumerate(axes): ax.set_ylabel(ylabel[i])
plt.tight_layout()
plt.subplots_adjust(top=0.95)
plot.suptitle('title')
}}}
Line 12: Line 36:
''.add_segments_bar()'' を使う([[https://gwpy.github.io/docs/latest/examples/miscellaneous/open-data-spectrogram.html|ここ]]を参照)。 ''.add_segments_bar()'' を使う([[https://gwpy.github.io/docs/latest/examples/miscellaneous/open-data-spectrogram.html|ここ]]を参照)。<<BR>>

Plotの描画関連

複数の時系列を縦に並べてplotする

ここに書いてある、gwpy.plotのPlot()がオススメ。
注意点は、TimeSeriesのlistやTimeSeriesDictを引数にしてまとめて渡した場合は separate=True をしても分割されないという謎仕様。面倒だが1つ1つ手で並べる必要がある。

   1 from gwpy.plot import Plot
   2 plot = Plot(l1hoft, h1hoft)
   3 plot = Plot(l1hoft, h1hoft, separate=True, sharex=True)
   4 plot.show()

https://gwpy.github.io/docs/stable/_images/plot-7.png

戻り値 (ここでは plot)は、matplotlibのfigureだと思ってしまってよい。
なので、それぞれのy軸ラベルや全体のタイトルを付けるには以下のようにする。

   1 import matplotlib.pyplot as plt
   2 axes = plot.get_axes()
   3 ylabel = ['y1','y2']
   4 for i, ax in enumerate(axes): ax.set_ylabel(ylabel[i])
   5 plt.tight_layout()
   6 plt.subplots_adjust(top=0.95)
   7 plot.suptitle('title')

時刻の基準を手で設定する

ここを参照

   1 ax = plot.gca()
   2 ax.set_epoch(1126259462) # GPS timeを入れる

DQ Flagを添える

.add_segments_bar() を使う(ここを参照)。
他にも .add_state_segments().add_dataqualityflag() といった似たものがある。詳細はPlotting APIを参照。 https://gwpy.github.io/docs/latest/_images/open-data-spectrogram-5.png

matplotlib色々

プロットの複雑なレイアウトはGridSpecが便利かも、という話

matplotlibで一定区間に背景色をつける方法

KAGRA/Subgroups/PEM/PythonMemoJP/plot (last edited 2021-08-11 15:28:39 by tatsuki.washimi)