MTgeophysics / mtpy

Python toolbox for standard Magnetotelluric (MT) data analysis
GNU General Public License v3.0
147 stars 66 forks source link

V2 bug: Cannot import MtPy, problem interfacing with matplotlib #183

Open k-a-mendoza opened 1 year ago

k-a-mendoza commented 1 year ago

Installed MtPy 2.0 beta via "pip install git+https://github.com/MTgeophysics/mtpy.git@v2"

upon trying to import MtPy in any way, I get the following error:

>>>from mtpy.core.mt import MT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/__init__.py", line 25, in <module>
    from mtpy.core.mt import MT
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/core/mt.py", line 20, in <module>
    from mtpy.imaging import PlotMTResponse, PlotPhaseTensor, PlotPenetrationDepth1D
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/imaging/__init__.py", line 2, in <module>
    from .plot_mt_response import PlotMTResponse
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/imaging/plot_mt_response.py", line 20, in <module>
    from mtpy.imaging.mtplot_tools import (
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/imaging/mtplot_tools/__init__.py", line 4, in <module>
    from .plot_settings import PlotSettings
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/imaging/mtplot_tools/plot_settings.py", line 18, in <module>
    import mtpy.imaging.mtcolors as mtcl
  File "/home/kmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/mtpy/imaging/mtcolors.py", line 284, in <module>
    cmapdict.update(cm.cmap_d)
AttributeError: module 'matplotlib.cm' has no attribute 'cmap_d'

For reference, I have matplotlib '3.7.1' installed. This is on python 3.9.16

kujaku11 commented 1 year ago

@k-a-mendoza Thanks. Still working through things obviously. Matplotlib has changed a lot of things the last few years and colormaps are one of them. I'd maybe try a lower version of Matplotlib looks like 3.5.3 is when the change occurred. I added the matplotlib version to the setup.py file. Hopefully that works now.

k-a-mendoza commented 1 year ago

Ah makes sense. Yeah downgrading helped, though it caused me to require a lower python version to be consistent with the other packages.

One possible interim fix could be to add a

try:
    from matplotlib.cm import cmap_d
except Exceptio as e:
    print("could not import matplotlib.cm. May not be needed")

kinda sloppy but could be helpful if people want to say, use MtPy for the data processing and their own visualization routines separately. Alternately, I could see what needs to be done to update those sections to be compatible with more modern matplotlib usage.

Nagarjuna013 commented 1 year ago

I have also faced this issue. I tried the above suggestions, but I'm unsuccessful. Kindly help me in this regard. AttributeError: module 'matplotlib.cm' has no attribute 'cmap_d' Installed Python version: 3.11 and Matplotlib version: 3.7.2