【问题标题】:plotly histogram subplot size绘制直方图子图大小
【发布时间】:2022-10-16 07:39:03
【问题描述】:

我想用 ploty 创建 20 个子图直方图,但整体图的大小不是最佳的:

from plotly.subplots import make_subplots
import plotly.graph_objs as go

data = [some data]
fig = make_subplots(rows=len(data), cols=1, shared_xaxes=True,
                    vertical_spacing=0.02, row_heights=[50] * 20)
p = 1                   
for i in data:
    fig.append_trace(go.Histogram(x=i), row=p, col=1)
    p += 1
    
fig.show()

情节如下所示:

我想在地块之间留出更多空间并增加子地块的高度。我尝试使用垂直间距和行高参数,但绘图没有更新。

如何增加子图的高度和它们之间的空间?

【问题讨论】:

  • 在这种情况下,可以在扩展原始图形的大小后调整此间距。目前默认大小是固定的,这就是原因。例如fig.update_layout(autosize=False,height=1000,width=800)

标签: python plotly histogram subplot


【解决方案1】:

同意@r-beginners,您必须使用尺寸选项才能使图看起来正确。我之前用过两种方式,在fig.update_layout()中设置大小或者在fig.write_image()中导出图片。

更新图像:

fig.update_layout(
    autosize=False,
    width=1920,
    height=2000)

导出图像:

fig.write_image('histograms.pdf',
    width=1920, 
    height=2000)

【讨论】:

    猜你喜欢
    • 2017-01-31
    • 2012-04-13
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多