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!

TABLES WITH GRAPHS, from Python API LIBRARIES

Hi,

The “TABLES WITH GRAPHS” from https:// plot.ly/python/table/, is its code most up to date?

I tried it (via copy & paste) but get the error: name 'Data' is not defined. Can someone confirm this please?

Also, how to make the graph on top of the table, instead of on the right?

Thanks

Thanks so much for pointing out that error
It should be go.Data, i.e.:
# Add trace data to figure figure['data'].extend(go.Data([trace1, trace2]))

Thanks, That works.

how to make the graph on top of the table, instead of on the right?

I tried myself, as below, but the table is missing header, and the graph label is wrong too.
Can you update the tutorial with another example to show how to make the graph on top of the table please?

Thanks

import plotly.plotly as py
import plotly.graph_objs as go
from plotly.tools import FigureFactory as FF

# Add table data
table_data = [['Team', 'Wins', 'Losses', 'Ties'],
			  ['Montréal<br>Canadiens', 18, 4, 0],
			  ['Dallas Stars', 18, 5, 0],
			  ['NY Rangers', 16, 5, 0], 
			  ['Boston<br>Bruins', 13, 8, 0],
			  ['Chicago<br>Blackhawks', 13, 8, 0],
			  ['LA Kings', 13, 8, 0],
			  ['Ottawa<br>Senators', 12, 5, 0]]
# Initialize a figure with FF.create_table(table_data)
figure = FF.create_table(table_data, height_constant=60)

# Add graph data
teams = ['Montréal Canadiens', 'Dallas Stars', 'NY Rangers',
		 'Boston Bruins', 'Chicago Blackhawks', 'Ottawa Senators']
GFPG = [3.54, 3.48, 3.0, 3.27, 2.83, 2.45, 3.18]
GAPG = [2.17, 2.57, 2.0, 2.91, 2.57, 2.14, 2.77]
# Make traces for graph
trace1 = go.Scatter(x=teams, y=GFPG,
					marker=dict(color='#0099ff'),
					name='Goals For<br>Per Game',
					xaxis='x2', yaxis='y2')
trace2 = go.Scatter(x=teams, y=GAPG,
					marker=dict(color='#404040'),
					name='Goals Against<br>Per Game',
					xaxis='x2', yaxis='y2')

# Add trace data to figure
figure['data'].extend(go.Data([trace1, trace2]))

# Edit layout for subplots
figure.layout.yaxis.update({'domain': [0, .45]})
figure.layout.yaxis2.update({'domain': [0.6, 1.]})
# The graph's yaxis MUST BE anchored to the graph's xaxis
figure.layout.yaxis2.update({'anchor': 'x2'})
figure.layout.yaxis2.update({'title': 'Goals'})
# Update the margins to add a title and see graph x-labels. 
figure.layout.margin.update({'t':50, 'b':100})
figure.layout.update({'title': '2016 Hockey Stats'})

# Plot!
plot_url = py.plot(figure, filename='subplot_table')

Yep this can be a little tricky. I’ve updated the doc: https://plot.ly/python/table/ with a vertical example.

THANKS A LOT!

Really appreciate it.

Ehmm…, chelsea,

I did a comparison and put the 'LA Kings' back, and found that it shows up in table but misses from the graph.

You are aware of this issue and still working on it, right?

thanks

You’d have to add them into the chart data as well (the chart and table display different data) i.e.

# Add graph data teams = ['Montréal Canadiens', 'Dallas Stars', 'NY Rangers', 'Boston Bruins', 'Chicago Blackhawks', 'LA Kings', 'Ottawa Senators'] GFPG = [3.54, 3.48, 3.0, 3.27, 2.83, 2.45, 3.18] GAPG = [2.17, 2.57, 2.0, 2.91, 2.57, 2.14, 2.77]

Oh, oh, I’m sorry, silly me. Thanks.

Hi I have a query that I cannot figure how to get a table with just one broad header - in a way a merged cell at the top, below which I can have different values for multiple columns…am in a crunch…any help will be greatly appreciated !!!Thanks !

Hi, So I figured this one…I gave the value of a blank in the header and it served the purpose. I have one more query, can I have different column widths for different columns in the table…? Like predefined widths…?

That’s not possible at this time