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

How to plot Bubble chart from crosstab?

How can I plot a bubble chart from a dataframe that has been created from a pandas crosstab of another dataframe?

The crosstab was created using;

df = pd.crosstab(raw_data['Speed'], raw_data['Height'].fillna('n/a'))

The df contains mostly zeros, however where a number appears I want a point where the value controls the point size. I want to set the Index values as the x axis and the columns name values as the Y axis.

I’ve tried using scatter & Scatter but can’t see where I’m going wrong.

The df would look something like;

             10    20    30    40    50
    1000     0     0    0      0     5
    1100     0     0    0      7     0
    1200     1     0    3      0     0
    1300     0     0    0      0     0
    1400     5     0    0      0     0

I’ve tried using scatter & Scatter like this;

fig.add_trace(go.Scatter(x=df.index.values, y=df.columns.values, mode='markers', marker_size=df.values),
              row=1, col=3)

This returned a TypeError: ‘Module’ object not callable. Full Traceback;

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1434, i
n _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/1HZ.py", line 301, in <module>
     fig.add_trace(go.scatter(x=df_trq.index, y=df_trq.columns,     marker_size=df_trq.values),
TypeError: 'module' object is not callable

Given this df, there would be 5 points on the scatter chart at varying sizes.

Any help is really appreciatted. Thanks