0

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()
Sash7
  • 73
  • 1
  • 11

2 Answers2

0

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.

Derek O
  • 16,770
  • 4
  • 24
  • 43
  • Thank you for the response. I tried running the code by setting the height to 20000px, however, it is leading to blank space in the supposed plotting area. If I increase the pixel size by 8000, it works, and I see no change in size of subplots. Is there a code to adjust the height of these subplots? – Sash7 Apr 28 '22 at 22:05
  • I am not sure if subplots can easily be individually adjusted – i'll circle back on this when i have some free time – Derek O Apr 29 '22 at 14:56
0

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.

thevoiddancer
  • 385
  • 2
  • 9