Problems using dayplot and section types in plotting

Hello everyone,

I have a problem using dayplot and section types in plotting, it doesn’t work in jupyter notebook!

The following error is generates when section type is used:

KeyError                                  Traceback (most recent call last)
File ~\anaconda3\envs\obspy\lib\site-packages\obspy\core\util\attribdict.py:142, in AttribDict.__getattr__(self, name, default)
    141 try:
--> 142     return self.__getitem__(name, default)
    143 except KeyError as e:

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\core\trace.py:232, in Stats.__getitem__(self, key, default)
    231 else:
--> 232     return super(Stats, self).__getitem__(key, default)

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\core\util\attribdict.py:97, in AttribDict.__getitem__(self, name, default)
     96 try:
---> 97     return self.__dict__[name]
     98 except KeyError:
     99     # check if we got any default value given at class level

KeyError: 'distance'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
File ~\anaconda3\envs\obspy\lib\site-packages\obspy\imaging\waveform.py:1170, in WaveformPlotting.__sect_init_traces(self)
   1169     for _i, tr in enumerate(self.stream):
-> 1170         self._tr_offsets[_i] = tr.stats.distance
   1171 except Exception:

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\core\util\attribdict.py:144, in AttribDict.__getattr__(self, name, default)
    143 except KeyError as e:
--> 144     raise AttributeError(e.args[0])

AttributeError: distance

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Input In [21], in <cell line: 1>()
----> 1 tr.plot(type='section')

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\core\trace.py:941, in Trace.plot(self, **kwargs)
    939 from obspy.imaging.waveform import WaveformPlotting
    940 waveform = WaveformPlotting(stream=self, **kwargs)
--> 941 return waveform.plot_waveform(**kwargs)

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\imaging\waveform.py:271, in WaveformPlotting.plot_waveform(self, *args, **kwargs)
    269     self.plot_day(*args, **kwargs)
    270 elif self.type == 'section':
--> 271     self.plot_section(*args, **kwargs)
    272 else:
    273     self.plot(*args, **kwargs)

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\imaging\waveform.py:1075, in WaveformPlotting.plot_section(self, *args, **kwargs)
   1071 """
   1072 Plots multiple waveforms as a record section on a single plot.
   1073 """
   1074 # Initialise data and plot
-> 1075 self.__sect_init_traces()
   1076 ax, lines = self.__sect_init_plot()
   1078 # Setting up line properties

File ~\anaconda3\envs\obspy\lib\site-packages\obspy\imaging\waveform.py:1175, in WaveformPlotting.__sect_init_traces(self)
   1171     except Exception:
   1172         msg = 'trace.stats.distance undefined ' +\
   1173               '(set before plotting [in m], ' +\
   1174               'or use the ev_coords argument)'
-> 1175         raise ValueError(msg)
   1176 else:
   1177     # Define offset as degree from epicenter
   1178     try:

ValueError: trace.stats.distance undefined (set before plotting [in m], or use the ev_coords argument)

<Figure size 1000x600 with 0 Axes>

How do I fix this issue??

Did you set the distances as showcased in the Tutorial?

https://docs.obspy.org/master/tutorial/code_snippets/waveform_plotting_tutorial.html?highlight=source%20code#plotting-a-record-section