bokeh-将图作为svg(valueerror:outputdocument for Expection to trupection of Expection furect of Expection furect of Expection furect of Models序列)
我在Bokeh中制作了一个绘图,但是当我尝试将其导出为SVG文件时,我会收到以下错误:OutputDocument For Expect for Tresection tocument for Outs tocument。
我的代码是:
# plot 2D histogram
def plot_hist(ch1, ch2, ch1_name='G3BP1', ch2_name='Nucleocapsid'):
'''Plot a 2D histogram from two channels'''
# get histogram data
df_hist = pd.DataFrame({ch1_name: ch1.ravel(), ch2_name: ch2.ravel()})
df_hist = df_hist.groupby(df_hist.columns.tolist()).size().reset_index(name='count')
df_hist['log count'] = np.log10(df_hist['count'])
# make the plot
return hv.VLine(10).opts(apply_ranges=True, line_width=2, color = 'black', line_dash = 'dashed') * hv.HLine(10).opts(apply_ranges=True, line_width=2, color = 'black', line_dash = 'dashed')*hv.Points(
data=df_hist, kdims=['G3BP1', 'Nucleocapsid'], vdims=['log count'],
).opts(
size=10,
cmap='magma',
color='log count',
colorbar=True,
colorbar_opts={"title": "log₁₀ count"},
frame_height=500,
frame_width=500,
padding=0.05,
xlabel='G3BP1',
ylabel='Nucleocapsid',
fontsize=15,
)
# make ROI mask
roi1_nt = (single_cell_roi_rCh[1] > 0) | (single_cell_roi_gCh[1] > 0)
roi1_nt = skimage.morphology.remove_small_objects(roi1_nt, min_size=3)
hv.renderer('bokeh').theme = 'caliber'
plot=plot_hist(im_r[roi1_nt], im_g[roi1_nt])
from bokeh.io import export_svgs
plot.output_backend = "svg"
export_svgs(plot, filename = "plot.svg")
最终是否有一种方法可以在带有Geotiff的TIFF文件中转换此图中保存的PNG文件?
事先感谢您的帮助。
I made a plot in Bokeh but when I try to export it as a svg file I get the following error: OutputDocumentFor expects a sequence of Models.
My code is:
# plot 2D histogram
def plot_hist(ch1, ch2, ch1_name='G3BP1', ch2_name='Nucleocapsid'):
'''Plot a 2D histogram from two channels'''
# get histogram data
df_hist = pd.DataFrame({ch1_name: ch1.ravel(), ch2_name: ch2.ravel()})
df_hist = df_hist.groupby(df_hist.columns.tolist()).size().reset_index(name='count')
df_hist['log count'] = np.log10(df_hist['count'])
# make the plot
return hv.VLine(10).opts(apply_ranges=True, line_width=2, color = 'black', line_dash = 'dashed') * hv.HLine(10).opts(apply_ranges=True, line_width=2, color = 'black', line_dash = 'dashed')*hv.Points(
data=df_hist, kdims=['G3BP1', 'Nucleocapsid'], vdims=['log count'],
).opts(
size=10,
cmap='magma',
color='log count',
colorbar=True,
colorbar_opts={"title": "log₁₀ count"},
frame_height=500,
frame_width=500,
padding=0.05,
xlabel='G3BP1',
ylabel='Nucleocapsid',
fontsize=15,
)
# make ROI mask
roi1_nt = (single_cell_roi_rCh[1] > 0) | (single_cell_roi_gCh[1] > 0)
roi1_nt = skimage.morphology.remove_small_objects(roi1_nt, min_size=3)
hv.renderer('bokeh').theme = 'caliber'
plot=plot_hist(im_r[roi1_nt], im_g[roi1_nt])
from bokeh.io import export_svgs
plot.output_backend = "svg"
export_svgs(plot, filename = "plot.svg")
Is there eventually a way to transform the png file saved from this plot in a tiff file with Geotiff?
Thanks in advance for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在使用
holoviews
在函数plot_hist()
中创建图。这不是bokeh对象
。请尝试调用
hv.render()
获取基础的散景图。下面的行应创建一个SVG文件。
edit
作为@bigreddot Metioned,
bokeh
还具有export_png()
工具。在这种情况下,代码看起来像下面。如果您的目标是从“ PNG”生成“ TIFF”文件,则可以从此 so 的问题。
如果PNG具有α值,这可能会带来一些问题。在这种情况下,请检查此问题关于在枕头中打开PNG。
It looks like you are using
holoviews
to create the figure in your functionplot_hist()
. This is not bokehobject
.Please try to call
hv.render()
to get the underlying bokeh figure.The lines below should create a svg file.
Edit
As @bigreddot metioned,
bokeh
also has aexport_png()
tool. In this case the code shhould look like below.If your goal is to generate an "tiff" file from "png", you can follow the solution from this question on SO.
If the png has an alpha value, this could bring some problems. In this case, check this question about open a png in Pillow.