Python Forum
plotly.graph_objs - Scatter mode error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plotly.graph_objs - Scatter mode error
#1
Hi:

I'm working on a project (I'm new to Python) and am stuck at a method - any help will be greatly appreciated.
This is the portion that is error-ing out

monthly_close = resample_prices(close)
project_helper.plot_resampled_prices(
    monthly_close.loc[:, apple_ticker],
    close.loc[:, apple_ticker],
    '{} Stock - Close Vs Monthly Close'.format(apple_ticker))
Error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in 3 monthly_close.loc[:, apple_ticker], 4 close.loc[:, apple_ticker], ----> 5 '{} Stock - Close Vs Monthly Close'.format(apple_ticker)) f:\hidden\project_helper.py in plot_resampled_prices(df_resampled, df, title) 68 traces = _generate_traces([ 69 ('Monthly Close', df_resampled, helper.color_scheme['major_line']), ---> 70 ('Close', df, helper.color_scheme['minor_line'])]) 71 offline_py.iplot({'data': traces, 'layout': layout}, config=config) 72 f:\hidden\project_helper.py in _generate_traces(name_df_color_data) 22 y=df, 23 mode='line', ---> 24 line={'color': color})) 25 return traces 26 f:\hidden\Python\lib\site-packages\plotly\graph_objs\__init__.py in __init__(self, arg, cliponaxis, connectgaps, customdata, customdatasrc, dx, dy, error_x, error_y, fill, fillcolor, groupnorm, hoverinfo, hoverinfosrc, hoverlabel, hoveron, hovertemplate, hovertemplatesrc, hovertext, hovertextsrc, ids, idssrc, legendgroup, line, marker, meta, metasrc, mode, name, opacity, orientation, r, rsrc, selected, selectedpoints, showlegend, stackgaps, stackgroup, stream, t, text, textfont, textposition, textpositionsrc, textsrc, texttemplate, texttemplatesrc, tsrc, uid, uirevision, unselected, visible, x, x0, xaxis, xcalendar, xsrc, y, y0, yaxis, ycalendar, ysrc, **kwargs) 38026 self["metasrc"] = metasrc if metasrc is not None else _v 38027 _v = arg.pop("mode", None) > 38028 self["mode"] = mode if mode is not None else _v 38029 _v = arg.pop("name", None) 38030 self["name"] = name if name is not None else _v f:\hidden\Python\lib\site-packages\plotly\basedatatypes.py in __setitem__(self, prop, value) 3488 # ### Handle simple property ### 3489 else: -> 3490 self._set_prop(prop, value) 3491 3492 # Handle non-scalar case f:\hidden\Python\lib\site-packages\plotly\basedatatypes.py in _set_prop(self, prop, val) 3775 return 3776 else: -> 3777 raise err 3778 3779 # val is None f:\hidden\Python\lib\site-packages\plotly\basedatatypes.py in _set_prop(self, prop, val) 3770 validator = self._validators.get(prop) 3771 try: -> 3772 val = validator.validate_coerce(val) 3773 except ValueError as err: 3774 if self._skip_invalid: f:\hidden\Python\lib\site-packages\_plotly_utils\basevalidators.py in validate_coerce(self, v) 1865 validated_v = self.vc_scalar(v) 1866 if validated_v is None: -> 1867 self.raise_invalid_val(v) 1868 1869 v = validated_v f:\hidden\Python\lib\site-packages\_plotly_utils\basevalidators.py in raise_invalid_val(self, v, inds) 281 typ=type_str(v), 282 v=repr(v), --> 283 valid_clr_desc=self.description(), 284 ) 285 ) ValueError: Invalid value of type 'builtins.str' received for the 'mode' property of scatter Received value: 'line' The 'mode' property is a flaglist and may be specified as a string containing: - Any combination of ['lines', 'markers', 'text'] joined with '+' characters (e.g. 'lines+markers') OR exactly one of ['none'] (e.g. 'none')
The entire project can be seen here -- https://github.com/mehta-a/AI-For-Tradin...0(1).ipynb
the

def _generate_traces(name_df_color_data):
    traces = []

    for name, df, color in name_df_color_data:
        traces.append(go.Scatter(
            name=name,
            x=df.index,
            y=df,
            mode='line',
            line={'color': color}))
    return traces
I'm using Visual Studio Code with Jupyter notebook
here is the pip list

Package Version
------------------ ------------
-cipy 1.4.1
-umpy 1.18.1
astroid 2.1.0
attrs 19.3.0
backcall 0.1.0
bleach 3.1.0
certifi 2019.6.16
chardet 3.0.4
chart-studio 1.0.0
colorama 0.4.1
colour 0.1.5
cvxpy 1.0.3
cycler 0.10.0
data 0.4
DateTime 4.3
dbfpy 2.3.1
decorator 4.4.1
defusedxml 0.6.0
dill 0.3.1.1
ecos 2.0.7.post1
entrypoints 0.3
eyeD3 0.8.9
fastcache 1.1.0
funcsigs 1.0.2
future 0.18.2
idna 2.6
importlib-metadata 1.4.0
ipykernel 5.1.3
ipython 7.11.1
ipython-genutils 0.2.0
ipywidgets 7.5.1
isort 4.3.4
jedi 0.15.2
Jinja2 2.10.3
joblib 0.14.1
json5 0.9.2
jsonschema 3.2.0
jupyter 1.0.0
jupyter-client 5.3.4
jupyter-console 6.1.0
jupyter-core 4.6.1
jupyterlab 2.0.1
jupyterlab-server 1.0.7
kiwisolver 1.1.0
lazy-object-proxy 1.3.1
lxml 4.4.2
MarkupSafe 1.1.1
mathjax 0.1.2
matplotlib 3.1.3
mccabe 0.6.1
mistune 0.8.4
more-itertools 8.1.0
multiprocess 0.70.9
nbconvert 5.6.1
nbformat 5.0.3
notebook 6.0.2
numpy 1.18.1
osqp 0.6.1
pandas 0.25.3
pandas-datareader 0.8.1
pandocfilters 1.4.2
parso 0.5.2
patsy 0.5.1
pickleshare 0.7.5
pip 20.0.2
plotly 4.5.4
prometheus-client 0.7.1
prompt-toolkit 3.0.2
Pygments 2.5.2
pylint 2.2.2
pyparsing 2.2.0
pyrsistent 0.15.7
python-dateutil 2.6.1
python-magic 0.4.15
pytz 2017.3
pywin32 227
pywinpty 0.5.7
pyzmq 18.1.1
qtconsole 4.6.0
requests 2.18.4
retrying 1.3.3
scikit-learn 0.22.2.post1
scipy 1.4.1
scs 2.1.1.post2
Send2Trash 1.5.0
setuptools 46.0.0
six 1.12.0
statsmodels 0.11.1
terminado 0.8.3
testpath 0.4.4
toolz 0.10.0
tornado 6.0.3
tqdm 4.43.0
traitlets 4.3.3
urllib3 1.22
wcwidth 0.1.8
webencodings 0.5.1
widgetsnbextension 3.5.1
wrapt 1.10.11
xlrd 1.2.0
zipp 1.0.0
zope.interface 4.7.1
Reply
#2
any help on this please - I'm still not able to see the issue :(
It is complaining on this function I believe - not sure what it could be ... any help will be appreciated - thanks
def _generate_traces(name_df_color_data):
    traces = []
 
    for name, df, color in name_df_color_data:
        traces.append(go.Scatter(
            name=name,
            x=df.index,
            y=df,
            mode='line',
            line={'color': color}))
    return traces
Reply
#3
Quote:The entire project can be seen here -- https://github.com/mehta-a/AI-For-Tradin...0(1).ipynb
Please post here, in appropriate bbcode tags. Your post will often get ignored unless all is immediately available. There are many posts that need to be attended to each day and only a handful of moderators to answer all, so any help is appreciated.
Reply
#4
Thanks for the response - however the solution in the link Project Solution Link is not working. Hence posted here for any help.
It might have something to do with the version of plotly or an environment issue maybe ?
Reply
#5
The version of plotly that you're using requires ipwidgets 7.5 (which you haveinstalled) and jupyterlab 1.2
Quote:JupyterLab Support (Python 3.5+)

For use in JupyterLab, install the jupyterlab and ipywidgets packages using pip...

pip install jupyterlab==1.2 "ipywidgets==7.5"
you're running jupyterlab 2.0.1. I can't say if that's a problem, but needs looking into.
perhaph there's mor on the github repository here: https://plot.ly/python/

also was built for python 3.7.1, but is probably ok if your version is newer.
you can tell from commandline (arg is capital V):
python -V
Reply
#6
Appreciate being at this --
I'm on Python version 3.7.2
I ran pip install jupyterlab==1.2 "ipywidgets==7.5" but still get the same error

I made changes to the code but still get the same error
def _generate_traces(name_df_color_data):
    traces = []

    for name, df, color in name_df_color_data:
        traces.append(go.Scatter(
            name=name,
            x=df.index,
            y=df,
            mode='markers',
            lines={'color': color}))

    return traces
updated mode = 'markers' from 'line' and made line={'color': color} to lines={'color': color}
still

ValueError:
Invalid value of type 'builtins.str' received for the 'mode' property of scatter
Received value: 'line'
not sure where it is getting 'line' from ! Huh
Reply
#7
You just answered your own question. Look at line 9 and remove comma at end!
Reply
#8
line 9 & 10 reads

mode='markers',
lines={'color': color}))

if I remove the comma after 'markers' then it will error out Huh

the error currently I'm getting is


ValueError:
Invalid value of type 'builtins.str' received for the 'mode' property of scatter
Received value: 'line'


I'm not sure where mode is receiving 'line' from ?
Reply
#9
nevertheless, remove the comma from line 9 and retry.
It is possible for the interpreter to lose the line number when a linw in not properly formatted.
Reply
#10
still no luck - same error :(
quite baffled at the error !

\S
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked plt.scatter() errors asja2010 0 1,473 Oct-13-2022, 08:15 AM
Last Post: asja2010
  binning_endpoints ->plotly Luis_liverpool 0 833 Aug-09-2022, 10:13 AM
Last Post: Luis_liverpool
  How to invert scatter plot axis Mark17 3 2,506 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  things that work in terminal mode but not in sublime mode alok 4 2,880 Aug-11-2021, 07:02 PM
Last Post: snippsat
  plotly expression problem Visiting 2 1,999 May-16-2021, 12:28 AM
Last Post: Visiting
  Animated scatter plot maximan 0 1,640 Jan-18-2021, 03:53 PM
Last Post: maximan
  Group scatter plots Mekala 0 1,645 Jul-23-2020, 02:18 PM
Last Post: Mekala
  error while running in debug mode ModuleNotFoundError avipy123 0 2,622 Jul-14-2020, 02:05 PM
Last Post: avipy123
  how to nest loop for 4*4 scatter plot kassamohammed 0 2,571 Jun-23-2020, 09:47 AM
Last Post: kassamohammed
  How to create Custom Buttons for 3D Scatter plots in Plotly? yourboyjoe 0 2,133 Jun-01-2020, 10:58 PM
Last Post: yourboyjoe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020