Python 如何在jupyter单元格中显示完整图形,并导出完整图像而不是嵌入图像的一部分?

Python 如何在jupyter单元格中显示完整图形,并导出完整图像而不是嵌入图像的一部分?,python,pandas,plotly,Python,Pandas,Plotly,我已生成一个plotly表,并尝试导出嵌入的表。但它只导出表的一部分。有谁能告诉我如何在jupyter单元格中显示整个表并正确导出它?谢谢 我尝试导出表的方式是: import os if not os.path.exists("imagesplotly"): os.mkdir("imagesplotly") fig.write_image("imagesplotly/fig2.pdf") 您可以通过在fig.write\u image中设置height来调整pdf表格,如下fig

我已生成一个plotly表,并尝试导出嵌入的表。但它只导出表的一部分。有谁能告诉我如何在jupyter单元格中显示整个表并正确导出它?谢谢

我尝试导出表的方式是:

import os

if not os.path.exists("imagesplotly"):
    os.mkdir("imagesplotly")

fig.write_image("imagesplotly/fig2.pdf")

您可以通过在
fig.write\u image
中设置
height
来调整pdf表格,如下
fig.write\u image(“C://imagespotly//fig1.pdf”,height=youredheight)

代码1-图:

import plotly.graph_objects as go
import numpy as np

np.random.seed(123)
lst1=np.random.uniform(low=0, high=100, size=10).tolist()
lst2=np.random.uniform(low=0, high=100, size=10).tolist()

fig = go.Figure(data=[go.Table(cells=dict(values=[np.random.rand(100,1), np.random.rand(100,1)]))])
fig.show()
pix = 225
datasize = len(lst1)

fig.write_image("C://imagesplotly//fig1.pdf", height=pix*datasize)
Jupyter输出:

import plotly.graph_objects as go
import numpy as np

np.random.seed(123)
lst1=np.random.uniform(low=0, high=100, size=10).tolist()
lst2=np.random.uniform(low=0, high=100, size=10).tolist()

fig = go.Figure(data=[go.Table(cells=dict(values=[np.random.rand(100,1), np.random.rand(100,1)]))])
fig.show()
pix = 225
datasize = len(lst1)

fig.write_image("C://imagesplotly//fig1.pdf", height=pix*datasize)

我认为将plotly table行的默认像素数乘以数据长度是个好主意,但我无法计算默认值。它肯定不是
255
,但下面代码段中的设置将捕获整个表的长度为100的列表

代码2-pdf输出:

import plotly.graph_objects as go
import numpy as np

np.random.seed(123)
lst1=np.random.uniform(low=0, high=100, size=10).tolist()
lst2=np.random.uniform(low=0, high=100, size=10).tolist()

fig = go.Figure(data=[go.Table(cells=dict(values=[np.random.rand(100,1), np.random.rand(100,1)]))])
fig.show()
pix = 225
datasize = len(lst1)

fig.write_image("C://imagesplotly//fig1.pdf", height=pix*datasize)
pdf输出(缩写):

import plotly.graph_objects as go
import numpy as np

np.random.seed(123)
lst1=np.random.uniform(low=0, high=100, size=10).tolist()
lst2=np.random.uniform(low=0, high=100, size=10).tolist()

fig = go.Figure(data=[go.Table(cells=dict(values=[np.random.rand(100,1), np.random.rand(100,1)]))])
fig.show()
pix = 225
datasize = len(lst1)

fig.write_image("C://imagesplotly//fig1.pdf", height=pix*datasize)