Closed
Description
Bug summary
I'm getting a weird error locally on my Mac in Jupyter Notebook while trying to plot the graph with matplotlib
.
The error is: AttributeError: module 'matplotlib' has no attribute 'pyplot'
even though everything is imported correctly and code works on Google Colab.
Code for reproduction
import librosa
import librosa.display
import matplotlib.pyplot as plt
def plot_mel_spectrogram(wav_file_path):
y, sr = librosa.load(wav_file_path, sr=None)
S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128)
log_S = librosa.power_to_db(S, ref=np.max)
plt.figure(figsize=(10, 4))
librosa.display.specshow(log_S, sr=sr, x_axis='time', y_axis='mel', cmap='coolwarm')
plt.title('Mel spectrogram')
plt.colorbar(format='%+02.0f dB')
plt.tight_layout()
plt.show()
Actual outcome
File ~/envs/venv39/lib/python3.9/site-packages/matplotlib/_api/__init__.py:226, in caching_module_getattr.<locals>.__getattr__(name)
224 if name in props:
225 return props[name].__get__(instance)
--> 226 raise AttributeError(
227 f"module {cls.__module__!r} has no attribute {name!r}")
AttributeError: module 'matplotlib' has no attribute 'axes'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File ~/envs/venv39/lib/python3.9/site-packages/matplotlib_inline/backend_inline.py:99, in show(close, block)
96 # only call close('all') if any to close
97 # close triggers gc.collect, which can be slow
98 if close and Gcf.get_all_fig_managers():
---> 99 matplotlib.pyplot.close('all')
File ~/envs/venv39/lib/python3.9/site-packages/matplotlib/_api/__init__.py:226, in caching_module_getattr.<locals>.__getattr__(name)
224 if name in props:
225 return props[name].__get__(instance)
--> 226 raise AttributeError(
227 f"module {cls.__module__!r} has no attribute {name!r}")
AttributeError: module 'matplotlib' has no attribute 'pyplot'
Expected outcome
Plotted graph of mel spectrogram.
Additional information
I tried to reinstall it and import it in different ways, but it didn't help.
Operating system
MacOS
Matplotlib Version
3.7.1
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.9.16
Jupyter version
6.5.3
Installation
pip