Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
k-a-mendoza opened this issue Mar 30, 2023 · 3 comments
Open

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

k-a-mendoza opened this issue Mar 30, 2023 · 3 comments

Comments

@k-a-mendoza
Copy link

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
Copy link
Collaborator

kujaku11 commented Apr 13, 2023

@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
Copy link
Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants