question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`box` value for Violin plot not available

See original GitHub issue

Hi,

the box parameter is not handled correctly. Trying to run the example of the website in a python console with plotly 2.5 installed leads to the following error (the example code is pasted after the error):

raceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/plotly/tools.py", line 1454, in return_figure_from_figure_or_data
    graph_objs.Figure(figure)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 1174, in __init__
    super(Figure, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 377, in __init__
    self.__setitem__(key, val, _raise=_raise)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 432, in __setitem__
    value = self._value_to_graph_object(key, value, _raise=_raise)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 543, in _value_to_graph_object
    _parent=self, _parent_key=key)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 793, in create
    return globals()[class_name](*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 158, in __init__
    value = self._value_to_graph_object(index, value, _raise=_raise)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 1076, in _value_to_graph_object
    _parent_key=index, **value)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 799, in create
    return PlotlyDict(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 377, in __init__
    self.__setitem__(key, val, _raise=_raise)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 432, in __setitem__
    value = self._value_to_graph_object(key, value, _raise=_raise)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 543, in _value_to_graph_object
    _parent=self, _parent_key=key)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 799, in create
    return PlotlyDict(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 372, in __init__
    self['type'] = self._name
  File "/usr/local/lib/python3.5/dist-packages/plotly/graph_objs/graph_objs.py", line 428, in __setitem__
    raise exceptions.PlotlyDictKeyError(self, path)
plotly.exceptions.PlotlyDictKeyError: 'type' is not allowed in 'box'

Path To Error: ['data'][0]['box']['type']

Valid attributes for 'box' at path ['data'][0]['box'] under parents ['figure', 'data', 'violin']:

    []

Run `<box-object>.help('attribute')` on any of the above.
'<box-object>' is the object at ['data'][0]['box']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "<string>", line 26, in <module>
  File "/usr/local/lib/python3.5/dist-packages/plotly/offline/offline.py", line 469, in plot
    '100%', '100%', global_requirejs=False)
  File "/usr/local/lib/python3.5/dist-packages/plotly/offline/offline.py", line 161, in _plot_html
    figure_or_data, validate
  File "/usr/local/lib/python3.5/dist-packages/plotly/tools.py", line 1464, in return_figure_from_figure_or_data
    "".format(err))
plotly.exceptions.PlotlyError: Invalid 'figure_or_data' argument. Plotly will not be able to properly parse the resulting JSON. If you want to send this 'figure_or_data' to Plotly anyway (not recommended), you can set 'validate=False' as a plot option.
Here's why you're seeing this error:

'type' is not allowed in 'box'

Path To Error: ['data'][0]['box']['type']

Valid attributes for 'box' at path ['data'][0]['box'] under parents ['figure', 'data', 'violin']:

    []

Run `<box-object>.help('attribute')` on any of the above.
'<box-object>' is the object at ['data'][0]['box']

Plot code:

import plotly
import plotly.graph_objs as go

f2 = [6.81, 6.78, 6.49, 6.72, 6.88, 7.68, 7.69, 7.38, 6.76, 6.84, 6.91, 6.74, 6.77, 6.73, 6.68, 6.94, 6.72]


fig = {
    "data": [{
        "type": 'violin',
        "y": f2,
        "box": {
            "visible": True
        },
        "line": {
            "color": 'black'
        },
        "meanline": {
            "visible": True
        },
        "fillcolor": '#8dd3c7',
        "opacity": 0.6,
        "x0": 'Total Bill'
    }],
    "layout" : {
        "title": "",
        "yaxis": {
            "zeroline": False,
        }
    }
}

plotly.offline.plot(fig)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
empetcommented, Jul 5, 2018

@rosswait With the last plotly version (pip install plotly==3.0.0.rc11) the violin plot works properly: https://plot.ly/~empet/14908

0reactions
jonmmeasecommented, Sep 22, 2018

Closing for now as this issue is reported to have been fixed in version 3. Feel free to open a new issue against version 3 if this is not the case. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Violin Plots | Tutorial by Chartio
Violin plots are used to compare the distribution of data between groups. Learn how violin plots are constructed and how to use them...
Read more >
Combined box-violin plot not aligned [duplicate] - Stack Overflow
There is an answer to this question here: how to align violin plots with boxplots. You can use the position argument to shift...
Read more >
Violin plots explained - Towards Data Science
In general, violin plots are a method of plotting numeric data and can be considered a combination of the box plot with a...
Read more >
Violin Plots 101: Visualizing Distribution and Probability Density
The box plot is an old standby for visualizing basic distributions. It's convenient for comparing summary statistics (such as range and ...
Read more >
Violin plots - GraphPad Prism 9 User Guide
Violin plots show the median and quartiles, as box-and-whisker plots do. But violin plots do a much better job of showing the distribution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found