I know I am beating a dead horse here, but I simply can't get the matplotlib plot to display in a Jupyterlab notebook.
I am trying to run a python script that eventually plots inside a jupyter cell.
Things I have tried:
- The best success that I had was with the
%run
magic command:%run pythonscript.py
. This then threw an error, but still was able to display a plot after it:
/opt/conda/lib/python3.9/site-packages/IPython/core/pylabtools.py in
mpl_execfile(fname, *where, **kw)
187 matplotlib.interactive(is_interactive)
188 # make rendering call now, if the user tried to do it
--> 189 if plt.draw_if_interactive.called:
190 plt.draw()
191 plt.draw_if_interactive.called = False
AttributeError: 'function' object has no attribute 'called'
However this was short-lived as it then just showed the error with no plot after a kernel restart.
%matplotlib inline
!python/!python3 pythonscript.py
No error. Nothing not even the `[[Figure 2D....]]%matplotlib notebook
!python/!python3 pythonscript.py
No error. Nothing not even the `[[Figure 2D....]]Without the
%matplotlib
magic command. No error. Nothing not even the `[[Figure 2D....]]%run pythonscript.py
. We get theAttributeError
as shown above.%pylab inline
yields nothing if coupled with!python pythonscript.py
and yields theAttributeError
if with%run
.%matplotlib inline
%run pythonscript.py
. We get theAttributeError
as shown above.
Trying to learn more about the attribute error when running the magic command yielded deadends.
pip list:
ipympl 0.7.0
ipython 7.27.0
jupyterlab 3.1.10
ipykernel 6.4.1
ipywidgets 7.6.4
jupyterlab-widgets 1.0.1
matplotlib 3.2.2
prompt-toolkit 3.0.20
At this point, I think I have exhausted most resources. Any advice would be appreciated.
Edit: Request screenshots and code explanation:
The code is based off of BackTrader, a backtesting library. The line of code that does the plotting is cerebro.plot()
. Docs: https://www.backtrader.com/docu/plotting/plotting/