Black Lives Matter. Please consider donating to Black Girls Code today.

Plotting returns data type issues

I am quite new to plotly, hopefully this is not too silly of a question.

Pulling data from mysql:

df = pd.DataFrame( [[ij for ij in i] for i in results] )
df.rename(columns={0: 'checkin_time', 1: 'license', 2: 'licensed_endpoints', 3: 'total_endpoints'}, inplace=True);
df = df.sort_values(['checkin_time'], ascending=[0]);


checkin_time	license	licensed_endpoints	total_endpoints
0	2020-02-26 21:58:28	2264483e-102a-4280-b7a2-8d2dd716936b	340000.0	77085.0
1	2020-02-20 23:49:54	2264483e-102a-4280-b7a2-8d2dd716936b	256000.0	43918.0
2	2020-02-13 23:40:04	2264483e-102a-4280-b7a2-8d2dd716936b	240000.0	43035.0
3	2020-02-06 23:42:51	2264483e-102a-4280-b7a2-8d2dd716936b	240000.0	64893.0
4	2020-01-30 23:54:08	2264483e-102a-4280-b7a2-8d2dd716936b	240000.0	80067.0

Now I want to plot, actually I would like to graph the checkin_time as X and both the licensed_endpoints and total_endpoints as Y on a bar chart or something. However, I cannot even get one of them to work using Figure.

When I setup the trace:

trace1 = go.Figure(

I always get a type error:

TypeError                                 Traceback (most recent call last)
<ipython-input-17-233aeadd3e03> in <module>
      1 trace1 = go.Figure(
      2     x=df['checkin_time'],
----> 3     y=df['licensed_endpoints']

~/.pyenv/versions/3.7.5/lib/python3.7/site-packages/plotly/ in __init__(self, data, layout_plotly, frames, skip_invalid, **kwargs)
    276                 self[k] = v
    277             elif not skip_invalid:
--> 278                 raise TypeError("invalid Figure property: {}".format(k))
    280     # Magic Methods

TypeError: invalid Figure property: x

Any ideas where I am going wrong?

Many thanks

Hi @spollock,

the go.Figure class only accepts a list of traces such as go.Scatter(), go.Line() etc… You code should look like.

trace1 = go.Scatter(

fig = go.Figure(data=[trace1])

Maybe as a new user of plotly you should spend a little time reading the documentation to understand how the library works :wink: This will make things much easier.

This would be a good start:

Thats exactly my code, you might spend a little time looking at the post. Make things much easier.

No, it is not the same code!!

you are trying to pass the x parameter to go.Figure() instead of passing it to go.Scatter()

1 Like