Lack of "plt.style.use('./deeplearning.mplstyle')"

I’m having difficulty running the labs due to the lack of “plt.style.use(‘./deeplearning.mplstyle’)”. I use VSCode.

I request guidance on how to run it locally.

Did you download the entire workspace folder? Or just the notebook. That could be the reason.

I believe that’s covered in the course FAQ.

Yes, I downloaded all the content. For example, if I run:
import numpy as np
%matplotlib widget
import matplotlib.pyplot as plt
from plt_one_addpt_onclick import plt_one_addpt_onclick
from lab_utils_common import draw_vthresh
plt.style.use(‘./deeplearning.mplstyle’)

I receive as an error:


ModuleNotFoundError Traceback (most recent call last)
/home/raphael/Documents/Machine Learning Specialization - Stanford/Files C1_W3/home/jovyan/work/C1_W3_Lab02_Sigmoid_function_Soln.ipynb Cell 2 line 2
1 import numpy as np
----> 2 get_ipython().run_line_magic(‘matplotlib’, ‘widget’)
3 import matplotlib.pyplot as plt
4 from plt_one_addpt_onclick import plt_one_addpt_onclick

File ~/anaconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2414, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2412 kwargs[‘local_ns’] = self.get_local_scope(stack_depth)
2413 with self.builtin_trap:
→ 2414 result = fn(*args, **kwargs)
2416 # The code below prevents the output from being displayed
2417 #when using magics with decodator @output_can_be_silenced
2418 # when the last Python token in the expression is a ‘;’.
2419 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/anaconda3/lib/python3.11/site-packages/IPython/core/magics/pylab.py:99, in PylabMagics.matplotlib(self, line)
97 print("Available matplotlib backends: s" backends_list)
98 else:
—> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)

File ~/anaconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py:3600, in InteractiveShell.enable_matplotlib(self, gui)
3596 print(‘Warning: Cannot change to a different GUI toolkit: %s.’

File :1176, in find_and_load(name, import)

File :1140, in find_and_load_unlocked(name, import)

ModuleNotFoundError: No module named ‘ipympl’

From your message, it looks like you just need to install ipympl.
You could do that with
pip install ipympl
Kindly go through the course FAQ for more info.
I also use VSCode and it works for me.

1 Like

@ Raphael_Garcia_Morei
one more thing you can do is, just remove the plt.style.use(). I think, this doesn’t affect the result but the styles of graphs plotting is not as the team of this course sepecified. Go with this and inform the result later here.
Thank you,

Got it, ‘./deeplearning.mplstyle’ Thank You.