镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

make_subplots crashes if vertical_spacing is set #2273

Closed

Description

@kerese

BUG REPORT

plotly version: 4.5.4
python version: 3.6.9

Calling make_subplots with the following parameter will make it crash.

figSubplots = make_subplots(
    rows=12, cols=1, shared_xaxes=True, vertical_spacing=0.1
)

With rows = 11 it still works. Between 11 rows there are 10 spacings, it means that the sum of the all spacings is 10 x 0.1 = 1.0. I tried some combination. Whenever this sum is over 1.0 the function crashes.
I assume that vertical_spacing leads to some kind of overflow.

The traceback shows the following:

Traceback (most recent call last):

  __File "./plot_results.py", line 50, in <module>
    rows=rows, cols=1, shared_xaxes=True, vertical_spacing=0.1
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/subplots.py", line 685, in make_subplots
    layout, subplot_type, secondary_y, x_domain, y_domain, max_subplot_ids
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/subplots.py", line 1057, in _init_subplot
    layout, secondary_y, x_domain, y_domain, max_subplot_ids
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/subplots.py", line 921, in _init_subplot_xy
    layout[yaxis_name] = y_axis
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 4437, in __setitem__
    super(BaseLayoutHierarchyType, self).__setitem__(prop, value)
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 3482, in __setitem__
    self._set_compound_prop(prop, value)
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 3836, in _set_compound_prop
    val = validator.validate_coerce(val, skip_invalid=self._skip_invalid)
  File "/home/kerese/.local/lib/python3.6/site-packages/_plotly_utils/basevalidators.py", line 2444, in validate_coerce
    v = self.data_class(v, skip_invalid=skip_invalid)
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/graph_objs/layout/__init__.py", line 3055, in __init__
    self["domain"] = domain if domain is not None else _v
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 3490, in __setitem__
    self._set_prop(prop, value)
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 3777, in _set_prop
    raise err
  File "/home/kerese/.local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 3772, in _set_prop
    val = validator.validate_coerce(val)
  File "/home/kerese/.local/lib/python3.6/site-packages/_plotly_utils/basevalidators.py", line 2172, in validate_coerce
    v[i] = validator.validate_coerce(el)
  File "/home/kerese/.local/lib/python3.6/site-packages/_plotly_utils/basevalidators.py", line 787, in validate_coerce
    self.raise_invalid_val(v)
  File "/home/kerese/.local/lib/python3.6/site-packages/_plotly_utils/basevalidators.py", line 283, in raise_invalid_val
    valid_clr_desc=self.description(),
ValueError: 
    Invalid value of type 'builtins.float' received for the 'domain[0]' property of layout.yaxis
        Received value: 1.0083333333333333

    The 'domain[0]' property is a number and may be specified as:
      - An int or float in the interval [0, 1]__

Activity

  1. empet commented on Mar 13, 2020

    @empet

    Plotly places all subplots within a square [0,1] x [0,1], and then maps this square onto the plot window, defined by your layout settings. If your vertical_spacing=0.1 then 11*0.1=1.1 is greater than the square height. That's why you got the displayed error
    Here is an example that can suggest how to tune your vertical_spacing, and go.layout.width, go.layout.height to get your figure:

    fig = make_subplots(rows=12, cols=1,  vertical_spacing=0.015)
    fig.update_layout(width=600, height=1400)
    for k in range(12):
        fig.add_trace(go.Scatter(x=[1,2,3,4], y=[2, 0.6, 1.8, 3] ), k+1, 1)
    
  2. nicolaskruchten commented on Mar 13, 2020

    @nicolaskruchten
    Contributor

    Thanks @empet! We should modify make_subplots to provide a clearer error message for this, though.

  3. gvwilson commented on Jun 14, 2024

    @gvwilson
    Contributor

    Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions