AttributeError after running Source code from "Tutorial » Merging Seismograms"

I downloaded the Source code (

from the page of “Tutorial » Merging Seismograms” (Merging Seismograms — ObsPy 1.3.0 documentation)

and ran it in my terminal and my jupyter notebook independently.

A). Run in my terminal: a message as “ UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.”

B). Run in my Jupyter notebook: error message shows at beginning is:
AttributeError Traceback (most recent call last)
Input In [1], in <cell line: 21>()
19 plt.subplot(4, 1, 4, sharex=ax)
20 plt.plot(st[0].times(), st[0].data, ‘r’)
—> 21

and the error message shows in the end is:
AttributeError: ‘NoneType’ object has no attribute ‘canvas’

I installed pyqt5 or replaced with plt.savefig(‘filename.png’), but they didn’t help.

My question is: should I install something else to solve this problem? or should I change the code somewhere to solve the issue?

Any possible way to solve the problem is appreciated.


Apparently this code snippet of the tutorial does not work with new matplotlib versions. I think if you delete lines 2 and 3 of the code it should work.

see docs: Fix merge seismograms tutorial by megies · Pull Request #3036 · obspy/obspy · GitHub which updates the example code snippet