我从文档中提取了两个示例代码,将它们组合起来,将代表实际的数据输出。
我想显示图形并将此数据保存在变量中。不作为HTML,也不将文件保存在Linux / Unix文件系统中。只是为了将数据保存在变量中。下面的无效示例代码。 (我用可视代码编写代码,然后将其粘贴到终端中。)
python
# CODE FOR TERMINAL
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral6
from bokeh.plotting import figure
from bokeh.transform import factor_cmap
from bokeh.io import export_svgs
from tempfile import TemporaryFile
output_file("bar_colormapped.html")
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
source = ColumnDataSource(data=dict(fruits=fruits, counts=counts))
p = figure(x_range=fruits, plot_height=350, toolbar_location=None, title="Fruit Counts")
p.vbar(x='fruits', top='counts', width=0.9, source=source, legend="fruits",
line_color='white', fill_color=factor_cmap('fruits', palette=Spectral6, factors=fruits))
p.xgrid.grid_line_color = None
p.y_range.start = 0
p.y_range.end = 9
p.legend.orientation = "horizontal"
p.legend.location = "top_center"
#show(p)
p.output_backend = "svg"
#export_svgs(p, filename="plot.svg")
t = TemporaryFile()
t = export_svgs(p, filename="plot.svg")
#t.write(p)
#t.seek(0)
#print(t.read())
代码的最后一行(show(p)及以下)是错误的!这就是为什么我写!如何将此类数据写入变量!?