Skip to content

ff.create_violin fails for multiple violins plot #1059

Closed
@ankitkariryaa

Description

@ankitkariryaa
>>> plotly.__version__
'3.0.0'

On plotly version 3.0.0, the multiple violin example(https://plot.ly/python/violin-plot/#multiple-violins) fails to run and throws the following error.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-ffcaed5bbabe> in <module>()
     17 df = pd.DataFrame(dict(Score = y, Group = gr))
     18 
---> 19 fig = ff.create_violin(df, data_header='Score', group_header='Group',height=500, width=800)
     20 py.iplot(fig, filename='Multiple Violins')

~/python3-general/lib/python3.6/site-packages/plotly/figure_factory/_violin.py in create_violin(data, data_header, group_header, colors, use_colorscale, group_stats, rugplot, sort, height, width, title)
    619                     data, data_header, group_header, valid_colors,
    620                     use_colorscale, group_stats, rugplot, sort,
--> 621                     height, width, title
    622                 )
    623                 return fig

~/python3-general/lib/python3.6/site-packages/plotly/figure_factory/_violin.py in violin_no_colorscale(data, data_header, group_header, colors, use_colorscale, group_stats, rugplot, sort, height, width, title)
    235         # add violin plot labels
    236         fig['layout'].update(
--> 237             {'xaxis{}'.format(k + 1): make_XAxis(group_name[k], plot_xrange)}
    238         )
    239 

~/python3-general/lib/python3.6/site-packages/plotly/basedatatypes.py in update(self, dict1, **kwargs)
   2824         if self.figure:
   2825             with self.figure.batch_update():
-> 2826                 BaseFigure._perform_update(self, dict1)
   2827                 BaseFigure._perform_update(self, kwargs)
   2828         else:

~/python3-general/lib/python3.6/site-packages/plotly/basedatatypes.py in _perform_update(plotly_obj, update_obj)
   2107             ]
   2108 
-> 2109             plotly_obj._raise_on_invalid_property_error(*invalid_props)
   2110 
   2111             # Process valid properties

~/python3-general/lib/python3.6/site-packages/plotly/basedatatypes.py in _raise_on_invalid_property_error(self, *args)
   2800                                  full_obj_name=full_obj_name,
   2801                                  invalid_str=invalid_str,
-> 2802                                  prop_descriptions=self._prop_descriptions))
   2803 
   2804     def update(self, dict1=None, **kwargs):

Here is the code for multiple violin plot example:

import plotly.plotly as py
import plotly.figure_factory as ff
from plotly.graph_objs import graph_objs

import numpy as np
import pandas as pd
from scipy import stats

np.random.seed(619517)
Nr = 250
y = np.random.randn(Nr)
gr = np.random.choice(list("ABCDE"), Nr)
norm_params = [(0, 1.2), (0.7, 1), (-0.5, 1.4), (0.3, 1), (0.8, 0.9)]

for i, letter in enumerate("ABCDE"):
    y[gr == letter] *= norm_params[i][1] + norm_params[i][0]
df = pd.DataFrame(dict(Score = y, Group = gr))

fig = ff.create_violin(df, data_header='Score', group_header='Group',
                       height=500, width=800)
py.iplot(fig, filename='Multiple Violins')

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions