Tobitor
Tobitor

Reputation: 1508

Getting a barplot instead of a Scatterplot in Dash

using this code

app.layout = html.Div([dcc.Graph(id='electricity',
                                figure= {'data':[
                                    go.Scatter(
                                    x=df['dayofweek'],
                                    y=df['Consumption [Wh]'],
                                    mode='markers')], 
                                'layout':go.Layout(title='Consumption per day',
                                                    xaxis = {'title':'dayofweek'},
                                                    yaxis = {'title':'Consumption'})})])

I get a Scatterplot using Dash. This is okay. But instead of a Scatterplot I am wondering how to get a Barplot here? I tried it by replacing go.Scatter by go.Bar but got a ValueError:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-5b5a80625894> in <module>
      1 app.layout = html.Div([dcc.Graph(id='electricity',
      2                                 figure= {'data':[
----> 3                                     go.Bar(
      4                                     x=df['dayofweek'],
      5                                     y=df['Consumption [Wh]'],

~\Downloads\WPy64-3920\python-3.9.2.amd64\lib\site-packages\plotly\graph_objs\_bar.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, legendgrouptitle, legendrank, marker, meta, metasrc, name, offset, offsetgroup, offsetsrc, opacity, orientation, outsidetextfont, selected, selectedpoints, showlegend, stream, text, textangle, textfont, textposition, textpositionsrc, textsrc, texttemplate, texttemplatesrc, uid, uirevision, unselected, visible, width, widthsrc, x, x0, xaxis, xcalendar, xhoverformat, xperiod, xperiod0, xperiodalignment, xsrc, y, y0, yaxis, ycalendar, yhoverformat, yperiod, yperiod0, yperiodalignment, ysrc, **kwargs)
   3250         # Process unknown kwargs
   3251         # ----------------------
-> 3252         self._process_kwargs(**dict(arg, **kwargs))
   3253 
   3254         # Reset skip_invalid

~\Downloads\WPy64-3920\python-3.9.2.amd64\lib\site-packages\plotly\basedatatypes.py in _process_kwargs(self, **kwargs)
   4335                 self[k] = v
   4336             elif not self._skip_invalid:
-> 4337                 raise err
   4338         # No need to call _raise_on_invalid_property_error here,
   4339         # because we have it set up so that the singular case of calling

ValueError: Invalid property specified for object of type plotly.graph_objs.Bar: 'mode'

Upvotes: 0

Views: 135

Answers (1)

bas
bas

Reputation: 15722

The error says what the problem is

ValueError: Invalid property specified for object of type plotly.graph_objs.Bar: 'mode'

go.Scatter has a mode property, but go.Bar doesn't. So remove the property if you want a bar chart.

Upvotes: 1

Related Questions