【问题标题】:How to show the full graph in a jupyter cell and export the full image instead of the part of the embedded image?如何在 jupyter 单元格中显示完整图形并导出完整图像而不是嵌入图像的一部分?
【发布时间】:2019-09-28 09:56:21
【问题描述】:

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

我尝试导出表格的方式是:

import os

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

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

【问题讨论】:

    标签: python pandas plotly


    【解决方案1】:

    您可以通过在fig.write_image 中设置height 来调整您的pdf 表格,就像这样fig.write_image("C://imagesplotly//fig1.pdf", height=yourDesiredHeight)

    代码 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()
    

    Jupyter 输出:

    我认为将绘图表行的默认像素数乘以数据长度是个好主意,但我无法弄清楚默认值。肯定不是255,但下面的 sn-p 中的设置将捕获整个表,以获得长度为 100 的列表。

    代码 2 - pdf 输出:

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

    pdf输出(略):

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 2017-10-16
      • 1970-01-01
      • 2012-04-29
      • 2023-03-25
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多