2014-09-19 15 views
6

Mi chiedo se sia possibile generare output HTML statici e grafici inline utilizzando Bokeh nello stesso notebook IPython. Quello che sto vedendo attualmente è che una volta chiamata o output_notebook() o output_file("myfile.html") sono bloccato usando quella modalità di output. Ad esempio, se inizialmente utilizzo output_notebook, successivamente chiamare output_file non crea un file di output.È possibile passare da output_notebook a output_file in una sessione di notebook IPython con Bokeh?

+0

Una correzione: Sembra che inizialmente possa usare 'output_file' seguito da' output_notebook', ma non viceversa. –

risposta

2

reset_output() prima del prossimo output_notebook o output_file chiamata lavora almeno nella versione 0.10.0.

# cell 1 
from bokeh.plotting import figure, show, output_notebook, output_file, reset_output 
p = figure(width=300, height=300) 
p.line(range(5), range(5)) 
output_notebook() 
show(p) 

# cell 2 
reset_output() 
output_file('foo.html') 
show(p) 

# cell 3 
reset_output() 
output_notebook() 
show(p) 

Primo e terzo spettacolo in notebook, secondi spettacoli nel browser.

0

È possibile creare un HTML statico utilizzando il seguente codice (adattato dall'esempio here):

from bokeh.plotting import figure 
from bokeh.resources import CDN 
from bokeh.embed import file_html 

plot = figure() 
plot.circle([1,2], [3,4]) 

html = file_html(plot, CDN, "my plot") 

with open('test.html', 'w') as f: 
    f.write(html) 

Questo funziona senza problemi in combinazione con output_notebook()

+0

Ho una situazione simile, ma i miei grafici sono creati in un ciclo. È possibile aggiungere ogni trama per creare un singolo file html con tutti i file su di esso? – mad5245

+0

Scusate per il trascurare. Stavo pensando molto a quello. Per riferimento è sufficiente cambiare la 'w' in 'a' proprio come con qualsiasi file. – mad5245

Problemi correlati