Python Forum
Error when running a matplot lib example
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when running a matplot lib example
#1
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()
Reply
#2
What are you running on?
Reply
#3
(Apr-23-2022, 05:11 PM)deanhystad Wrote: What are you running on?

I am running it on Fedora 35 , Spyder IDE
Reply
#4
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']
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error "cannot identify image file" part way through running hatflyer 0 681 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Error when running kivy on python janeik 8 2,069 Jun-16-2023, 10:58 PM
Last Post: janeik
  Matplot / numpy noisy data problem the57chambers 1 700 Feb-09-2023, 03:27 AM
Last Post: deanhystad
  Getting error when running "MINUS" between 2 databases marlonbown 4 1,279 Nov-10-2022, 05:49 AM
Last Post: deanhystad
  Error while running code on VSC maiya 4 3,776 Jul-01-2022, 02:51 PM
Last Post: maiya
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,375 Jun-18-2022, 01:09 PM
Last Post: snippsat
  How to save Matplot chart to temp file? Morkus 2 4,542 Jun-12-2021, 10:52 AM
Last Post: Morkus
  Keep getting Session management error when running imshow in pycharm pace 0 2,103 Mar-25-2021, 10:06 AM
Last Post: pace
  Error when running script on startup in Linux NoahTheNerd 0 1,974 Mar-07-2021, 04:54 PM
Last Post: NoahTheNerd
  Error when running mktorrent subprocess command pythonnewbie138 4 3,879 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020