Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Using Plotly to plot data from Postgre SQL database

Hello all,

I’m trying to plot a graph with time in Xaxis and Power( from my smart meter) in Yaxis.
time is in TEXT format ( Sat Jul 9 21:34:04 2016) and Power is in Float format (20.56)

i read these from the database and save it to an array
trace = py.Scatter(x=time,y=power)

and they use plotly offline to plot the graph

plotly.offline.plot(trace)

I get an error saying
" Invalid ‘figure_or_data’ argument. Plotly will not be able to properly parse the resulting JSON. If you want to send this ‘figure_or_data’ to Plotly anyways (not recommended), you can set ‘validate=False’ as a plot option.
Here is why you’re seeing this error:

Path to Error: ['y']

Valid attributes for 'figure' at path[] under parents[]:

['layout', 'data']

What is the error in the program?
I could plot by manually giving X and Y values.
Is it because of wrong time format?

Hi there,
It looks like you may be skipping the step of creating the data array.
So you could try:
trace = py.Scatter(x=time,y=power)
data = [trace]
plotly.offline.plot(data)

or

trace = py.Scatter(x=time,y=power)
plotly.offline.plot([trace])

You can find more information on the python getting started page: https://plot.ly/python/getting-started/#start-plotting-online //
https://plot.ly/python/getting-started/#initialization-for-offline-plotting