Problem plotting csv data: Attempt leads to 'TypeError: dict expected at most 1 arguments, got 2'

Hi,

I would like to plot csv data (where one column such as ‘X’ has shape (102791,)), leaning on https://plot.ly/python/user-guide/,

df = pd.read_csv(‘file.csv’)
x=df[‘X’]
y=df[‘Y’]

I guess that the length of X is too large so I’d like to plot only, say the 10 first elements.

In order to do this and to avoid problems with ‘dictionary format’ I create arrays
a = np.array([ i for i in range(10)]) instead of x (since the latter has a wronh format (time)), and
A = np.array([ y[i] for i in range(10)])

The printed values of these arrays are:

a = [0 1 2 3 4 5 6 7 8 9]
A = [ 252.62563 252.112328 252.966952 252.283861 252.865349 252.182848
251.283296 250.153394 252.018362 251.242277]

Then I try to plot these values using
import numpy as np
import pandas as pd
import csv
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(a[:],A[:], marker={‘color’: ‘red’, ‘symbol’: 104, ‘size’: “10”},
mode=“markers+lines”, text=[“one”], name=‘1st Trace’)
data=go.Data([trace1])
py.iplot(data, filename=‘simple-plot-from-csv’)

And no matter what I try get constantly the following error:

Traceback (most recent call last):
File “first.py”, line 119, in
mode=“markers+lines”, text=[“one”], name=‘1st Trace’)
File “/home/opt-user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly/graph_objs/graph_objs.py”, line 373, in init
d = {key: val for key, val in dict(*args, **kwargs).items()}
TypeError: dict expected at most 1 arguments, got 2

I would be most grateful for help.
Thank you!

Hi there,
It looks like you have not set x and y in your Scatter object. The following should work for you:

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
A = [ 252.62563, 252.112328, 252.966952, 252.283861, 252.865349, 252.182848,
251.283296, 250.153394, 252.018362, 251.242277]

import numpy as np
import pandas as pd
import csv
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(x=a, y=A, marker={'color': 'red', 'symbol': 104, 'size': "10"},
mode="markers+lines", text=["one"], name='1st Trace')
data=go.Data([trace1])
py.iplot(data, filename='simple-plot-from-csv')

You can find more scatter and line examples here:

https://plot.ly/python/line-and-scatter/ and https://plot.ly/python/line-charts/

Hi Chelsea,
Thank you for your reply.
I tried your suggestion but unfortunately I get another error message. I wonder if I did something wrong…

plot
[0 1 2 3 4 5 6 7 8 9] [ 252.62563 252.112328 252.966952 252.283861 252.865349 252.182848
251.283296 250.153394 252.018362 251.242277]
plot
Traceback (most recent call last):
File “first.py”, line 136, in
py.iplot(data, filename=‘simple-plot-from-csv’)
File “/home/opt-user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly/plotly/plotly.py”, line 151, in iplot
url = plot(figure_or_data, **plot_options)
File “/home/opt-user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly/plotly/plotly.py”, line 241, in plot
res = _send_to_plotly(figure, **plot_options)
File “/home/opt-user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly/plotly/plotly.py”, line 1376, in _send_to_plotly
validate_credentials(credentials)
File “/home/opt-user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly/plotly/plotly.py”, line 1325, in validate_credentials
raise exceptions.PlotlyLocalCredentialsError()
plotly.exceptions.PlotlyLocalCredentialsError:
Couldn’t find a ‘username’, ‘api-key’ pair for you on your local machine. To sign in temporarily (until you stop running Python), run:

import plotly.plotly as py
py.sign_in(‘username’, ‘api_key’)

Even better, save your credentials permanently using the ‘tools’ module:

import plotly.tools as tls
tls.set_credentials_file(username=‘username’, api_key=‘api-key’)

For more help, see Plotly Python Graphing Library.

Did I understand something wrong? Is this package not free?
Many thanks

Hi there,
We have options to use Plotly online or offline. When using Plotly online you need an account. We offer free or paid accounts. You can see our getting started page to see all of these options outlined: https://plot.ly/python/getting-started/