0

I have been trying to plot a table and a scatter plot side by side using plotly but to no avail for a long period. How can we do that?

How to plot table and scatter plots in plotly3.6?

I have tried this so far:

import numpy as np
import pandas as pd
import seaborn as sns
sns.set(color_codes=True)

import matplotlib.pyplot as plt
%matplotlib inline

import plotly
import plotly.offline as py
import plotly.plotly as pyp
import plotly.graph_objs as go
import plotly.figure_factory as ff
import plotly.tools as tls
from plotly.offline import plot, iplot, init_notebook_mode
init_notebook_mode(connected=False)

# subplots table
fig = tls.make_subplots(rows=1, cols=2, shared_xaxes=True)
trace1 = go.Scatter(x=[1,2,3],y=[1,2,3])
df = pd.DataFrame({'name':list('ABC'),
                  'salary': [1000,2000,3000]})


table = ff.create_table(df)
fig.append_trace(table, 1, 2)
py.iplot(fig)

But this does not work. However,
iplot(table) works.

How to fix the problem?

2 Answers 2

1

You are close but forgot the specs element. Also, you must specify positioning in .add_trace() with row=# and col=# Hope this helps.

    from plotly.subplots import make_subplots
    columns =['one','two']
    cellValues =['first piece of data', 'second piece of data']
    figure = make_subplots(
        rows = 1, cols  =2,
        specs=[[{"type":"table"},{"type" : "scatter"}]]
    )
    figure.add_trace(go.Table(header=dict(
        values = columns
        #other elements here
    ),cells=dict(
        values = cellValues
    ), row=1, col=1
    )
    figure.add_trace(go.Scatter(x=[1,2,3],y=[1,2,3]),row=1,col=2)
    )
Sign up to request clarification or add additional context in comments.

Comments

0

ff.create_table() creates a full Figure not a trace, so you can't append it to a pre-existing Figure. You'll have to go the other way and add the Scatter to the output of ff.create_table().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.