使用 embedpy 在 jupyterq 中将图形绘制成图像
Imaging plotly figure as image in jupyterq using embedpy
当我尝试将来自 pyhton 的绘图显示为工作正常的图像时
import plotly.express as px
from IPython.display import Image
fig = px.scatter(x=range(10), y=range(10))
Image(fig.to_image(format="png"))
但是,当我通过 jupyterq 的 embedpy 尝试相同的操作时,图表不会显示
px:.p.import[`plotly.express]
ipd:.p.import[`IPython.display]
fig:px[`:scatter][`x pykw til 10; `y pykw til 10]
img:fig[`:to_image][`format pykw `png]
ipd[`:Image][img]
图表不会显示。我也试过主动展示
ipd[`:display][ipd[`:Image][img]]
但这只显示了很小的通用图像缩略图
常规绘图显示良好
fig[`:show][]
此外,尝试通过 .p.e 执行 python 代码不显示图像,只显示缩略图
.p.e["import plotly.express as px"]
.p.e["from IPython.display import Image, display"]
.p.e["fig=px.scatter(x=range(10), y=range(10))"]
.p.e["Image(fig.to_image(format='png'))"]
.p.e["display(Image(fig.to_image(format='png')))"]
感谢您强调这个问题,目前我们还没有解决这个问题,但是 GitHub https://github.com/KxSystems/jupyterq/issues/55 上已经提出了一个问题,我们正在调查中。
问题似乎出在 .qpk.mc 函数中。同事提供的两种解决方法:
覆盖有问题的函数
.qpk.mc:{y}
注入一个可以处理编码字符串的html
ipd[`:display]ipd[`:HTML]["<img src=\"data:image/png;base64,",.b64.enc[img`],"\">"];
当我尝试将来自 pyhton 的绘图显示为工作正常的图像时
import plotly.express as px
from IPython.display import Image
fig = px.scatter(x=range(10), y=range(10))
Image(fig.to_image(format="png"))
但是,当我通过 jupyterq 的 embedpy 尝试相同的操作时,图表不会显示
px:.p.import[`plotly.express]
ipd:.p.import[`IPython.display]
fig:px[`:scatter][`x pykw til 10; `y pykw til 10]
img:fig[`:to_image][`format pykw `png]
ipd[`:Image][img]
图表不会显示。我也试过主动展示
ipd[`:display][ipd[`:Image][img]]
但这只显示了很小的通用图像缩略图
常规绘图显示良好
fig[`:show][]
此外,尝试通过 .p.e 执行 python 代码不显示图像,只显示缩略图
.p.e["import plotly.express as px"]
.p.e["from IPython.display import Image, display"]
.p.e["fig=px.scatter(x=range(10), y=range(10))"]
.p.e["Image(fig.to_image(format='png'))"]
.p.e["display(Image(fig.to_image(format='png')))"]
感谢您强调这个问题,目前我们还没有解决这个问题,但是 GitHub https://github.com/KxSystems/jupyterq/issues/55 上已经提出了一个问题,我们正在调查中。
问题似乎出在 .qpk.mc 函数中。同事提供的两种解决方法:
覆盖有问题的函数
.qpk.mc:{y}
注入一个可以处理编码字符串的html
ipd[`:display]ipd[`:HTML]["<img src=\"data:image/png;base64,",.b64.enc[img`],"\">"];