python – AttributeError: the module & # 39; plotly.validators.bar & # 39; does not have the & # 39; TexttemplateValidator & # 39; attribute


I want to draw eigs_vals:

(2.32775157e+01 9.52106403e+00 6.28218534e+00 2.60804365e+00
 1.67407407e+00 1.00262342e+00 5.63964139e-01 4.31472684e-01
 3.99892354e-01 3.20281596e-01 2.46599295e-01 2.25225326e-01
 1.83994543e-01 1.79463965e-01 1.26683975e-01 1.03432264e-01
 9.72929766e-02 8.28120655e-02 7.35903993e-02 6.27055135e-02
 5.88016984e-02 4.57564038e-02 4.48965154e-02 4.28743238e-02
 3.20052795e-02 2.99018556e-02 2.90188218e-02 2.80037766e-02
 2.68282699e-02 2.33288483e-02 2.15042615e-02 1.79092673e-02
 1.73475500e-02 1.59441557e-02 1.34669518e-02 1.18752995e-02
 1.06541795e-02 9.69474356e-03 3.26011905e-03 3.60308379e-03
 4.22570307e-03 8.35881929e-03 5.16595912e-03 5.49607218e-03
 7.51740009e-03 7.06741359e-03 6.04070480e-03 6.53525486e-03)

But with the following code that comes from plot.ly on the analysis of the main components:

tot = sum(eig_vals)
var_exp = ((i / tot)*100 for i in sorted(eig_vals, reverse=True))
cum_var_exp = np.cumsum(var_exp)

trace1 = dict(
    type='bar',
    x=('PC %s' %i for i in range(1,5)),
    y=var_exp,
    name='Individual'
)

trace2 = dict(
    type='scatter',
    x=('PC %s' %i for i in range(1,5)), 
    y=cum_var_exp,
    name='Cumulative'
)

data = (trace1, trace2)

layout=dict(
    title='Explained variance by different principal components',
    yaxis=dict(
        title='Explained variance in percent'
    ),
    annotations=list((
        dict(
            x=1.16,
            y=1.05,
            xref='paper',
            yref='paper',
            text='Explained Variance',
            showarrow=False,
        )
    ))
)

fig = dict(data=data, layout=layout)
plot(fig)#, 
     #filename='selecting-principal-components.html')

But I get:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in 
     37 
     38 fig = dict(data=data, layout=layout)
---> 39 plot(fig)#,
     40      #filename='selecting-principal-components.html')

C:ProgramDataAnaconda3libsite-packagesplotlyofflineoffline.py in plot(figure_or_data, show_link, link_text, validate, output_type, include_plotlyjs, filename, auto_open, image, image_filename, image_width, image_height, config, include_mathjax, auto_play, animation_opts)
    570             animation_opts=animation_opts)
    571 
--> 572 
    573 def plot_mpl(mpl_fig, resize=False, strip_style=False,
    574              verbose=False, show_link=False, link_text='Export to plot.ly',

C:ProgramDataAnaconda3libsite-packagesplotlytools.py in return_figure_from_figure_or_data(figure_or_data, validate_figure)
    551 
    552     # Throw exception if non-valid key / fill in defaults
--> 553     def _check_keys_and_fill(name, arg, defaults):
    554         def _checks(item, defaults):
    555             if item is None:

C:ProgramDataAnaconda3libsite-packagesplotlygraph_objs_figure.py in __init__(self, data, layout, frames, skip_invalid, **kwargs)
    606             constancy of data points during animation. Should be an
    607             array of strings, not numbers or any other type.
--> 608         idssrc
    609             Sets the source reference on plot.ly for  ids .
    610         legendgroup

C:ProgramDataAnaconda3libsite-packagesplotlybasedatatypes.py in __init__(self, data, layout_plotly, frames, skip_invalid, **kwargs)
    155         data = self._data_validator.validate_coerce(data,
    156                                                     skip_invalid=skip_invalid)
--> 157 
    158         # ### Save tuple of trace objects ###
    159         self._data_objs = data

C:ProgramDataAnaconda3libsite-packages_plotly_utilsbasevalidators.py in validate_coerce(self, v, skip_invalid)

C:ProgramDataAnaconda3libsite-packagesplotlygraph_objs__init__.py in __init__(self, arg, alignmentgroup, base, basesrc, cliponaxis, constraintext, customdata, customdatasrc, dx, dy, error_x, error_y, hoverinfo, hoverinfosrc, hoverlabel, hovertemplate, hovertemplatesrc, hovertext, hovertextsrc, ids, idssrc, insidetextanchor, insidetextfont, legendgroup, marker, meta, metasrc, name, offset, offsetgroup, offsetsrc, opacity, orientation, outsidetextfont, r, rsrc, selected, selectedpoints, showlegend, stream, t, text, textangle, textfont, textposition, textpositionsrc, textsrc, texttemplate, texttemplatesrc, tsrc, uid, uirevision, unselected, visible, width, widthsrc, x, x0, xaxis, xcalendar, xsrc, y, y0, yaxis, ycalendar, ysrc, **kwargs)

AttributeError: module 'plotly.validators.bar' has no attribute 'TexttemplateValidator'