Michael Jones
Michael Jones

Reputation: 77

Trouble with plotly charts

I am giving myself an intro to plotting data and have come across some trouble. I am working on a line chart that I plan on making animated as soon as I figure out this problem. I want a graph that looks like this:

However this code I have now:

`x=df_pre_2003['year']
 y=df_pre_2003['nAllNeonic']
 trace=go.Scatter(
     x=x,
     y=y
)
data=[trace]
ply.plot(data, filename='test.html')`

is giving me this: enter image description here So I added y=df_pre_2003['nAllNeonic'].sum() but, now it says ValueError: Invalid value of type 'builtins.float' received for the 'y' property of scatter Received value: 1133180.4000000006

The 'y' property is an array that may be specified as a tuple,
list, numpy array, or pandas Series

Which I tried and it still did not work. The data types for year is int64 and nAllNeonic is float64.

Upvotes: 4

Views: 8319

Answers (2)

HassanSh__3571619
HassanSh__3571619

Reputation: 2077

This is not to answer this question, but to share my similar case for any future research needs: In my case the error message was coming when I tried to export the django models objects to use it in the plotly scatter chart, and the error was as follows:

The 'x' property is an array that may be specified as a tuple, list, numpy array, or pandas Series

The solution for this in my case was to export the django model info into pandas data frame then use the pandas data frame columns instead of the model fields name.

Upvotes: 1

Michieldo
Michieldo

Reputation: 189

It looks like you have to sort the values first based on the date. Now it's connecting a value in the year 1997 with a value in 1994.

df_pre_2003.sort_values(by = ['year'])

Upvotes: 1

Related Questions