# Plot sizing problems

**URL:** <https://community.plotly.com/t/plot-sizing-problems/1620>\
**Category:** plotly.js\
**Created:** [July 22, 2016, 11:08am UTC](https://community.plotly.com/t/plot-sizing-problems/1620 "2016-07-22T11:08:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.plotly.com/u/chris)\
**Post date:** [July 22, 2016, 11:08am UTC](https://community.plotly.com/t/plot-sizing-problems/1620/1 "2016-07-22T11:08:23Z")

</div>

I am trying to arrange two charts on a page, dynamically sized to suit the available screen space. The first chart should be ~25% of the screen height. Between the charts, there is a fixed-height strip containing some buttons. The remainder of the screen should be used by the second chart. I have arranged via CSS flex layout for the container divs to behave as intended. As soon as I introduce a Plotly chart, the sizing is disrupted, seemingly no matter what hints I give to Plotly.

From my observations, these are equivalent:  
layout.autosize = undefined  
layout.autosize: “initial”

As are these:  
layout.autosize = true  
layout.autosize = false

It’s not clear what factors influences the autosizing algorithm. When autosize comes into play, it seems to always pick a height of 450px (which equates to a size greater than the parent div) and a width of 700px (which is less than the parent div). With autosize off, the width expands to fill the parent, but the height also clings to 450px.

I had hoped that taking a hint from [https://plot.ly/javascript/responsive-fluid-layout/](https://plot.ly/javascript/responsive-fluid-layout/) (but using 100% rather than 100vh) would help. It didn’t.

How do I make Plotly respect (and fill) the dimensions of it’s container? Fixed dimensions isn’t an option.

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [July 22, 2016, 2:05pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/2 "2016-07-22T14:05:59Z")

</div>

Interesting. Would you mind sharing a reproducible example to help us debug?

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [July 22, 2016, 2:07pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/3 "2016-07-22T14:07:09Z")

</div>

With `layout.autosize: true`, the plot _should_ fill us the whole graph div. Maybe something is up with how our autosize routine and a CSS flew layout interact? Thanks for writing in.

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.plotly.com/u/chris)\
**Post date:** [August 1, 2016, 1:02pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/4 "2016-08-01T13:02:42Z")

</div>

Apologies for the delay in responding etienne, I’ve been away from the office all of last week. I will endeavour to produce a small, self-contained example that demostrates the issue.

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.plotly.com/u/chris)\
**Post date:** [August 3, 2016, 2:30pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/5 "2016-08-03T14:30:47Z")

</div>

> Interesting. Would you mind sharing a reproducible example to help us debug?

This [Codepen](http://codepen.io/chris_waters/pen/LkJqLj) shows the behaviour.

With autosize not set, the width of the containing div is correctly consumed, but how the height is derived isn’t clear. Setting autosize: true stops the width being correct and causes the height to expand, breaking the layout.

Removing the two Plotly.plot(…) statements allows the desired layout to show itself.

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.plotly.com/u/chris)\
**Post date:** [August 5, 2016, 1:32pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/6 "2016-08-05T13:32:24Z")

</div>

(Replying directly to etienne rather than the topic as a whole as I’m not sure which actions causes notifications to be sent and I’m still very much stuck with this problem).

I’ve added a CodePen that illustrates the problem.

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [August 5, 2016, 2:03pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/7 "2016-08-05T14:03:50Z")

</div>

Hi @chris , sorry for not responding sooner.

I’ve been trying to write a good explanation of what’s going here, but to no avail yet. It’s the first time I’ve experimented plotly.js in a `flex` layout. I think something is up with our autosize routine, but I’m not 100% what exactly.

In the meantime, you might want to have a look at [https://plot.ly/javascript/responsive-fluid-layout/](https://plot.ly/javascript/responsive-fluid-layout/) if you haven’t already.

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.plotly.com/u/chris)\
**Post date:** [August 8, 2016, 7:53am UTC](https://community.plotly.com/t/plot-sizing-problems/1620/8 "2016-08-08T07:53:40Z")

</div>

I had seen that link (see my first comment), but I have switched to flex layout since the original posting so I just revisited it. In some ways it’s now closer to what I was hoping for (see [this CodePen](http://codepen.io/chris_waters/pen/dXQpgo)).

For me (Chrome on Windows 7), I see:

1. Layout is initially wrong (top chart doesn’t fill its div, and that div is already taller than desired.
2. Expanding the window height causes the two charts to correctly fill their divs.
3. Any height reduction causes the top chart and div to **grow** by a small number of pixels. The bottom div does not shrink, so bursts out of the containing div.
4. Either a window width increase **or** decrease causes the same effects as #3.

---

<div class="post-metadata">

**Author:** ![schivlg](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@schivlg](https://community.plotly.com/u/schivlg)\
**Post date:** [March 19, 2017, 1:52am UTC](https://community.plotly.com/t/plot-sizing-problems/1620/9 "2017-03-19T01:52:27Z")

</div>

Was this issue ever resolved? I’m seeing the same thing - plot height on load is 450px, no matter what the container size.

---

<div class="post-metadata">

**Author:** ![chris](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chris](https://community.plotly.com/u/chris)\
**Post date:** [March 20, 2017, 8:39am UTC](https://community.plotly.com/t/plot-sizing-problems/1620/10 "2017-03-20T08:39:41Z")

</div>

No.  
I’d like to thing support is better on a paid plan, but my experiences with this forum and the documentation did not convince me to invest.

---

<div class="post-metadata">

**Author:** ![schivlg](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@schivlg](https://community.plotly.com/u/schivlg)\
**Post date:** [March 20, 2017, 1:42pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/11 "2017-03-20T13:42:04Z")

</div>

Ok, thanks. I’ll try calculating the container height based on window size. Did you log an issue on github?

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jack/32/11_2.png) [@jack](https://community.plotly.com/u/jack)\
**Post date:** [May 15, 2017, 6:15am UTC](https://community.plotly.com/t/plot-sizing-problems/1620/12 "2017-05-15T06:15:30Z")

</div>

Hey @chris , plotly.js authors provide help here on a mostly volunteer basis. The point of the developer support plans is to guarantee \<24h responses and code solutions including quick plotly.js updates if needed. We can’t help out every single plotly.js developer, so use the support plans to prioritize:

> **[Javascript Support](https://support.plot.ly/libraries/javascript)**
>
> Plotly.js is an open source, high-level charting library built on top of d3.js and WebGL.

---

<div class="post-metadata">

**Author:** ![lars](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lars](https://community.plotly.com/u/lars)\
**Post date:** [September 1, 2017, 9:39pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/13 "2017-09-01T21:39:56Z")

</div>

I am having the same problem, its pretty frustrating, because making a web-based 3d-graph is the reason i invested in plotly/dash.

What i can add, that the 450 px shows up in the dom in svg elements:

```auto
<div class="svg-container" style="position: relative; width: 2932.92px; height: 450px;"><svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="2932.92" height="450" style="background: rgb(255, 255, 255);">

```

and

```auto
<svg class="main-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="2932.92" height="450" style="background: rgb(255, 255, 255);"><defs id="defs-37bd53"><g class="gradients">

```

If i change the 450 to something bigger manually, the graph follows suit.

btw: a bug is a bug and @chris went through the trouble of reproducing it.

---

<div class="post-metadata">

**Author:** ![eponym](https://avatars.discourse-cdn.com/v4/letter/e/919ad9/32.png) [@eponym](https://community.plotly.com/u/eponym)\
**Post date:** [September 25, 2017, 10:05pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/14 "2017-09-25T22:05:00Z")

</div>

I used the following to work around the bug (i.e. chart not resizing properly when window height reduced) - in my case the chart is in div#content, and I want it to be 40px shorter than full window due to header and footer. After calling Plots.resize() I check dimensions, and if not correct I set myself and call Plots.resize() again:

```auto
  (function() {
  var d3 = Plotly.d3;
  var gd3 = d3.select("div[id='content']");
  var gd = gd3.node();

  Plotly.plot(gd, [{
    type: 'bar',
    x: [1, 2, 3, 4],
    y: [5, 10, 2, 8],
    marker: {
      color: '#C8A2C8',
      line: {
        width: 2.5
      }
    }
  }], {
    title: 'Auto-Resize',
    font: {
      size: 16
    }
  });

  window.onresize = function() {
    Plotly.Plots.resize(gd);
    var window_height = window.innerHeight;
    var content_div_height = document.getElementById('content').offsetHeight;
    // workaround for bug in Plotly: when flexbox container gets smaller, graph does not shrink
    if (content_div_height > (window_height - 40)) {
      var svg_container = document.getElementById('content').getElementsByClassName('plot-container')[0].getElementsByClassName('svg-container')[0];
      svg_container.style.height = (window_height - 40) + 'px';
      Plotly.Plots.resize(gd);
    }
  };
  })();

```

my HTML:

```auto
<div id='outerdiv' style='display: flex;flex-direction: column; height: 100vh'>
    <div id='header' style='height: 20px; background:red'>foo</div>
    <div id='content' style='flex:1; background: white'></div>
    <div id='footer' style='height: 20px; background:blue'>baz</div>
</div>

```

---

<div class="post-metadata">

**Author:** ![gennadyi](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@gennadyi](https://community.plotly.com/u/gennadyi)\
**Post date:** [November 10, 2017, 5:52pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/15 "2017-11-10T17:52:28Z")

</div>

I am having same problem with spitting out a dcc.Graph through python Dash code  
and don’t know how to change the default 450px height on the chart. None of the settings I tried worked.

For your workaround you give JS code.  
How do I translate it to python or how should it related to the python code?

![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/e7a46768bc6612893c86e168079b04fd76ca59df.png)

---

<div class="post-metadata">

**Author:** ![Prom3theus](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@Prom3theus](https://community.plotly.com/u/Prom3theus)\
**Post date:** [November 24, 2017, 9:27pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/16 "2017-11-24T21:27:00Z")

</div>

Hello, Gennadiy, wondering if you’ve found an answer - my dcc.Graph is also stuck at 450px, which is frustrating. Thanks!

---

<div class="post-metadata">

**Author:** ![gennadyi](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@gennadyi](https://community.plotly.com/u/gennadyi)\
**Post date:** [December 1, 2017, 7:37pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/17 "2017-12-01T19:37:59Z")

</div>

Prom3theus,

Hi, try this: you can hardcode the height as CSS style to 920 for example:

dcc.Graph(id=‘chart-graph’, style={‘margin-top’: ‘0’, ‘height’: 920} )

I still haven’t found solution for dynamic height re-layout. Seems like there is a bug in some layer where width is being dynamically re-layouted but height is not. Let me know if that worked for you or if you find a better dynamic relayout solution.

---

<div class="post-metadata">

**Author:** ![gennadyi](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@gennadyi](https://community.plotly.com/u/gennadyi)\
**Post date:** [December 1, 2017, 7:40pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/18 "2017-12-01T19:40:45Z")

</div>

Also see my post here: [Can't seem to change default Height on Graph](https://community.plotly.com/t/cant-seem-to-change-default-height-on-graph/6742/3)

---

<div class="post-metadata">

**Author:** ![gennadyi](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@gennadyi](https://community.plotly.com/u/gennadyi)\
**Post date:** [December 4, 2017, 7:06pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/19 "2017-12-04T19:06:53Z")

</div>

@Prom3theus - Nikita see Chris’s response here: [Can’t seem to change default Height on Graph](https://community.plotly.com/t/cant-seem-to-change-default-height-on-graph/6742/7)

The viewport height in CSS seems to be the trick to solve this.

---

<div class="post-metadata">

**Author:** ![adm78](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@adm78](https://community.plotly.com/u/adm78)\
**Post date:** [January 4, 2018, 8:51pm UTC](https://community.plotly.com/t/plot-sizing-problems/1620/20 "2018-01-04T20:51:21Z")

</div>

eponym’s code worked perfectly for me using a css grid layout.

[Next page](https://community.plotly.com/t/plot-sizing-problems/1620.md?page=2)
