如何调整或设置Plotly Express Facet子图的大小?

发布于 2025-01-24 22:25:56 字数 692 浏览 5 评论 0原文

我正在使用Plotly Express来绘制我正在进行的分析所需的子图。由于工作的性质,我有30多个子图由faceting。我得到的图形如图所示。

我想增加每个方面图的大小,以使它们可以更好地可视化。请为我提供所需的帮助。

最低可再现代码:

fig = px.line(some_df, x='X', y='Y', color='Color label',
          facet_col = 'Color label',
          facet_col_wrap = 1,
          facet_row_spacing = 0.03,
          height = 5000,
          title = 'This is the title of my plot'
          )
fig.update_xaxes(matches=None, showticklabels = False)
fig.update_layout(yaxis_type="log")
fig.show()

I am using plotly express to plot the subplots that I require for the analysis I am doing. Due to the nature of the work I have more than 30 subplots resulting from faceting. The graphs that I am getting are as shown in the figure.

enter image description here

I would like to increase the size of each of these facet plots so that they are visualized better. Kindly provide me with the required help.

Minimum reproducible code:

fig = px.line(some_df, x='X', y='Y', color='Color label',
          facet_col = 'Color label',
          facet_col_wrap = 1,
          facet_row_spacing = 0.03,
          height = 5000,
          title = 'This is the title of my plot'
          )
fig.update_xaxes(matches=None, showticklabels = False)
fig.update_layout(yaxis_type="log")
fig.show()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绳情 2025-01-31 22:25:56

当前有30个子图,每个子图获得了自己的行,高度为5000px,每个子图的高度大约为5000px/30 = 167px不是不是大量空间(由于子图之间的填充,实际高度较小)。您可以尝试将高度提高到20000px,这将使每个子图更高4倍。

另外,您可以尝试更改参数facet_col_wrap = 5,以便排更少。有30个子图,5列和6行,每行的子图将有更多的空间。

Currently with 30 subplots and each subplot getting its own row, with a height of 5000px, each subplot will have a height of roughly 5000px / 30 = 167px which isn't a lot of space (the actual height is smaller because of padding between the subplots). You could try increasing the height to 20000px, which would give each subplot 4x more height.

Alternatively, you can try changing the argument facet_col_wrap=5 so that there are fewer rows. With 30 subplots, and 5 columns and 6 rows, there will be more space for subplots in each row.

沫雨熙 2025-01-31 22:25:56

据我所知,无法单独设置方面。我的解决方法是重新计算整个刻面区域的高度,知道所需的刻面高度和行数(列和宽度也是如此)。但是,Plotly并未明确指定的公式用于计算尺寸,因此我所产生的方面有点较低(Plotly也取出了边距)。

我使用的公式是:

facet_height =(abore_height -reage_height * facet_row_spacing *
(number_of_rows -1)) / number_of_rows < / p>

重新计算时我得到:

afore_height = facet_height * number_of_rows /(1- facet_row_spacing *
(number_of_rows -1))

因此,对于5行个人高度200,我将获得1086 PX的总面积高度。但是,由于情节有利润,并且没有公式(即使是我从间距参数中拼凑在一起的第一个),因此所得的方面实际上不到200个PX。

希望这会有所帮助。

To the best of my knowledge, facets can't be individually set. My workaround was to recalculate the height of the whole facet area knowing the desired facet height and number of rows (same goes for columns and width). However, plotly doesn't have clearly stated formula it uses to calculate size, so my resulting facets are a bit lower (plotly takes out margins as well).

Formula I used was:

facet_height = (area_height - area_height * facet_row_spacing *
(number_of_rows - 1)) / number_of_rows

When recalculated I got:

area_height = facet_height * number_of_rows / (1 - facet_row_spacing *
(number_of_rows - 1))

So, for instance, for 5 rows of individual height 200 I'd get total facet height of 1086 px. But since plotly takes margin into account, and there's no formula for that (even the first one I pieced together from spacing argument), the resulting facets are actually under 200 px.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文