Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Not plotting in Jupyter Notebook? #278

Unanswered
eugeneyng asked this question in Q&A
Discussion options

Hi all,
Anybody experiencing a problem with Bokeh not plotting in Jupyter? I'm running the minimal example with Python 3.7.3, Jupyter Notebook 6.1.5, and Bokeh 2.3.0. I looked at some closed issues but the only solution was setting this line

backtesting.set_bokeh_output(notebook=False)

I tried true and false and neither worked. Anybody else having the same issue?

`
# In[1]:

 import backtesting
 import backtesting.lib
 import backtesting.test
 backtesting.set_bokeh_output(notebook=False)
 
 # In[2]:
 
 class SmaCross(backtesting.Strategy):
 n1 = 10
 n2 = 20
 
 def init(self):
 close = self.data.Close
 self.sma1 = self.I(backtesting.test.SMA, close, self.n1)
 self.sma2 = self.I(backtesting.test.SMA, close, self.n2)
 
 def next(self):
 if backtesting.lib.crossover(self.sma1, self.sma2):
 self.buy()
 elif backtesting.lib.crossover(self.sma2, self.sma1):
 self.sell()
 
 # In[3]:
 
 bt = backtesting.Backtest(backtesting.test.GOOG, SmaCross,
 cash=10000, commission=.002,
 exclusive_orders=True)
 bt.run()
 
 # In[4]:
 
 bt.plot()

`

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

I will say I am running the notebook on a Raspberry Pi and hosting the notebook publicly so that I can access it from my computer. Believe this is the issue. It's noted that I can set backtesting.set_bokeh_output(notebook=False) to False and can then open the html file separately. For now this is a fine workaround. Sorry if I'm taking up space on the forums here!

You must be logged in to vote
1 reply
Comment options

backtesting.set_bokeh_output(notebook=True) should be a working default for Jupyter notebooks.

The Bokeh resources are loaded from their remote CDN. Do you run an ad-blocker perhaps?

You should see an image like this upon any first backtesting import:
Screenshot_2021年03月14日_04-41-43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /