gwpy icon indicating copy to clipboard operation
gwpy copied to clipboard

Using gwpy.Spectrogram.plot with an existing axis

Open tttiago opened this issue 1 year ago • 0 comments

Is it possible to plot a gwpy.Spectrogram using the .plot() method in an already existing axis? This would be useful to create figures with multiple spectrograms.

I tried

time_windows = (0.5, 1.0, 2.0, 4.0)
specsgrams = {0.5: ..., 1.0: ..., 2.0: ..., 4.0: ...)
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 15))
for i, time_window in enumerate(time_windows):
   ax = axes.flatten()[i]
   specsgrams[time_window].plot(ax=ax)

but I get

TypeError: Axes.pcolormesh() got multiple values for argument 'ax'

Is there any alternative which does not involve directly calling ax.imshow() or ax.pcolormesh() and writing all the boilerplate code to handle ticks, scales, etc. ?

tttiago avatar Jun 18 '24 18:06 tttiago