An issue regarding spacing using fig.add_trace(go.Indicator(); how can I add enough spacing so titles of each fig do not overlap?

Viewed 112

I am having trouble with spacing for my visualization below. I intend to make just a simple text visualization that displays the counts of movies and tv shows. The problem I have is regarding the titles. When I assign each fig to a row/column, it is centering on the number being displayed, which makes the titles for each fig overlap. I tried adding more rows to space it out, but that caused more trouble than good. Is there a way to add more padding between each fig? I tried a few different things, but I am relatively unfamiliar to plotly and how everything comes together sometimes. Perhaps there is another way of doing this visualization and I am overcomplicating it. There is a link to my output below too.

fig = go.Figure()

fig.add_trace(go.Indicator(
    mode = "number",
    value = 12354,
    number={'font':{'color': '#00A8E1','size':85}},
    title = {"text": "Movies<br><span style='font-size:0.8em;color:gray'>On Prime Video</span>"},
    domain = {'row': 0,'column': 0}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 2144,
    number={'font':{'color': '#00A8E1','size':85}},
    title = {"text": "TV Shows<br><span style='font-size:0.8em;color:gray'>On Prime Video</span>"},
    domain = {'row': 0,'column': 1}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 3560,
    number={'font':{'color': '#E50914','size':70}},
    title = {"text": "Movies<br><span style='font-size:0.8em;color:gray'>On Netflix</span>"},
    domain = {'row': 1, 'column': 0}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 1931,
    number={'font':{'color': '#E50914','size':70}},
    title = {"text": "TV Shows<br><span style='font-size:0.8em;color:gray'>On Netflix</span>"},
    domain = {'row': 1, 'column': 1}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 903,
    number={'font':{'color': '#66AA33','size':60}},
    title = {"text": "Movies<br><span style='font-size:0.8em;color:gray'>On Hulu</span>"},
    domain = {'row': 2, 'column': 0}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 1754,
    number={'font':{'color': '#66AA33','size':60}},
    title = {"text": "TV Shows<br><span style='font-size:0.8em;color:gray'>On Hulu</span>"},
    domain = {'row': 2, 'column': 1}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 564,
    number={'font':{'color': '#113CCF','size':50}},
    title = {"text": "Movies<br><span style='font-size:0.8em;color:gray'>On Disney+</span>"},
    domain = {'row': 3, 'column': 0}))

fig.add_trace(go.Indicator(
    mode = "number",
    value = 180,
    number={'font':{'color': '#113CCF','size':50}},
    title = {"text": "TV Shows<br><span style='font-size:0.8em;color:gray'>On Disney+</span>"},
    domain = {'row': 3, 'column': 1}))


fig.update_layout(
    grid = {'rows': 4, 'columns': 2})

Result:

https://i.stack.imgur.com/XFfjT.png

1 Answers

You can use:

fig.update_layout(height = 800)

This isn't very dynamic, but replacing 800 with something that is termined by the number and size of the elements in your visualization is the way to go if it's too cumbersome to set it manually.

Result:

enter image description here

Related