geomagpy / magpy

MagPy (or GeomagPy) is a Python package for analysing and displaying geomagnetic data.
BSD 3-Clause "New" or "Revised" License
45 stars 27 forks source link

Magpy inline plots in jupyter #110

Closed Ensase closed 2 years ago

Ensase commented 2 years ago

Hi everyone! I've tried to plot loaded streams inside jupyter notebook:

%matplotlib inline
from magpy.stream import read
import magpy.mpplot as mp
stream = read(r'~/data/*.min')
mp.plot(stream)

The dedicated conda env with python 3.7 and magpy 1.0.3 used to run this code. I've got the error:

[/opt/anaconda3/envs/magpy1/lib/python3.7/site-packages/magpy/stream.py:1590](): VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  return DataStream(self,self.header,np.asarray(array))
[/opt/anaconda3/envs/magpy1/lib/python3.7/site-packages/magpy/mpplot.py:2480](): UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()

Could you suggest me how to use inline plots with magpy?

leonro commented 2 years ago

You might try to add the following line in order to use a different backend:

%matplotlib inline from magpy.stream import read import magpy.mpplot as mp

matplotlib.use('TkAgg')

stream = read(r'~/data/*.min') mp.plot(stream)

There are other supported backends as well like WXAgg, Qt5Agg...

leonro commented 2 years ago

Closing this now as the solution posted in February seems to be satisfying