Python Forum
Error when running a matplot lib example - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Error when running a matplot lib example (/thread-37020.html)



Error when running a matplot lib example - aurelius_nero - Apr-23-2022

Hi all,
New forum user here.
When I run this code from the Matplotlib examples, I get the following error:
Error:
Traceback (most recent call last): File /opt/intel/oneapi/intelpython/latest/envs/2022.0.2/lib/python3.9/site-packages/matplotlib/style/core.py:111 in use rc = rc_params_from_file(style, use_default_template=False) File /opt/intel/oneapi/intelpython/latest/envs/2022.0.2/lib/python3.9/site-packages/matplotlib/__init__.py:985 in rc_params_from_file config_from_file = _rc_params_in_file(fname, fail_on_error) File /opt/intel/oneapi/intelpython/latest/envs/2022.0.2/lib/python3.9/site-packages/matplotlib/__init__.py:916 in _rc_params_in_file with _open_file_or_url(fname) as fd: File /opt/intel/oneapi/intelpython/latest/envs/2022.0.2/lib/python3.9/contextlib.py:119 in __enter__ return next(self.gen) File /opt/intel/oneapi/intelpython/latest/envs/2022.0.2/lib/python3.9/site-packages/matplotlib/__init__.py:902 in _open_file_or_url with open(fname, encoding=encoding) as f: FileNotFoundError: [Errno 2] No such file or directory: '_mpl-gallery-nogrid' During handling of the above exception, another exception occurred: Traceback (most recent call last): File ~/Documents/Python/matplotlib_example1.py:4 in <module> plt.style.use('_mpl-gallery-nogrid') File /opt/intel/oneapi/intelpython/latest/envs/2022.0.2/lib/python3.9/site-packages/matplotlib/style/core.py:114 in use raise IOError( OSError: '_mpl-gallery-nogrid' not found in the style library and input is not a valid URL or path; see `style.available` for list of available styles
My Code:
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('_mpl-gallery-nogrid')

# make a stream function:
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
# make U and V out of the streamfunction:
V = np.diff(Z[1:, :], axis=1)
U = -np.diff(Z[:, 1:], axis=0)

# plot:
fig, ax = plt.subplots()

ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V)

plt.show()



RE: Error when running a matplot lib example - deanhystad - Apr-23-2022

What are you running on?


RE: Error when running a matplot lib example - aurelius_nero - Apr-23-2022

(Apr-23-2022, 05:11 PM)deanhystad Wrote: What are you running on?

I am running it on Fedora 35 , Spyder IDE


RE: Error when running a matplot lib example - Axel_Erfurt - Apr-24-2022

The style is not available, check the styles

import matplotlib.pyplot as plt
print(plt.style.available)
This is what I get in Mint

Output:
['seaborn-notebook', 'seaborn-pastel', 'fast', 'dark_background', 'Solarize_Light2', 'seaborn-talk', 'grayscale', 'seaborn-whitegrid', 'seaborn-dark', 'seaborn-colorblind', 'seaborn-ticks', 'seaborn-deep', 'seaborn-dark-palette', 'fivethirtyeight', 'bmh', 'seaborn-poster', 'seaborn-darkgrid', 'seaborn', '_classic_test', 'tableau-colorblind10', 'seaborn-bright', 'seaborn-white', 'seaborn-muted', 'classic', 'ggplot', 'seaborn-paper']