👀
Crash Visualization
  • Welcome
  • Preface
    • Who the book is written for
    • How the book is organized
  • 1. Introduction of Data Visualization
    • 1.1 What is data visualization?
    • 1.2 Why does visualization matter?
  • 2. Tricks in Visualization
    • 2.1 Choose Appropriate Chart
    • 2.2 Features of Charts
      • 2.2.1 Table
      • 2.2.2 Column Chart
      • 2.2.3 Line Chart
      • 2.2.4 Pie Chart
      • 2.2.5 Scatter Chart
      • 2.2.6 Map Chart
    • 2.3 Misused Graph
    • 2.4 Tips in Visualization
  • 3. Matplotlib
    • 3.1 Basic Concepts
    • 3.2 Line Chart
    • 3.3 Area Chart
    • 3.4 Column Chart
    • 3.5 Histogram Chart
    • 3.6 Scatter Chart
    • 3.7 Lollipop Chart
    • 3.8 Pie Chart
    • 3.9 Venn Chart
    • 3.10 Waffle Chart
    • 3.11 Animation
  • 4. Seaborn
    • 4.1 Trends
    • 4.2 Ranking
      • 4.2.1 Barplot
      • 4.2.2 Boxplot
    • 4.3 Composition
      • 4.3.1 Stacked Chart
    • 4.4 Correlation
      • 4.4.1 Scatter Plot
      • 4.4.2 Linear Relationship
      • 4.4.3 Heatmap
      • 4.4.4 Pairplot
    • 4.5 Distribution
      • 4.5.1 Boxplot
      • 4.5.2 Violin plot
      • 4.5.3 Histogram plot
      • 4.5.4 Density plot
      • 4.5.5 Joint plot
  • 5. Bokeh
    • 5.1 Basic Plotting
    • 5.2 Data Sources
    • 5.3 Annotations
    • 5.4 Categorical Data
    • 5.5 Presentation and Layouts
    • 5.6 Linking and Interactions
    • 5.7 Network Graph
    • 5.8 Widgets
  • 6. Plotly
    • 6.1 Fundamental Concepts
      • 6.1.1 Plotly Express
      • 6.1.2 Plotly Graph Objects
    • 6.2 Advanced Charts
      • 6.2.1 Advanced Scatter Chart
      • 6.2.2 Advanced Bar Chart
      • 6.2.3 Advanced Pie Chart
      • 6.2.4 Advanced Heatmap
      • 6.2.5 Sankey Chart
      • 6.2.6 Tables
    • 6.3 Statistical Charts
      • 6.3.1 Common Statistical Charts
      • 6.3.2 Dendrograms
      • 6.3.3 Radar Chart
      • 6.3.4 Polar Chart
      • 6.3.5 Streamline Chart
    • 6.4 Financial Charts
      • 6.4.1 Funnel Chart
      • 6.4.2 Candlestick Chart
      • 6.4.3 Waterfall Chart
  • Support
    • Donation
Powered by GitBook
On this page
  • Graph Objects
  • 1. Basic Table
  • 2. Customized Table
  • Figure Factory
  • 3. Basic Table
  • 4. Table with LaTeX
  • 5. Customized Table

Was this helpful?

  1. 6. Plotly
  2. 6.2 Advanced Charts

6.2.6 Tables

Previous6.2.5 Sankey ChartNext6.3 Statistical Charts

Last updated 4 years ago

Was this helpful?

There are two methods to create a table in Plotly. One is plotly.graph_objects, the other is plotly.figure_factory

Graph Objects

1. Basic Table

import plotly.graph_objects as go

fig = go.Figure(data=[go.Table(header=dict(values=['Jonas', 'Melo']),
                 cells=dict(values=[[100, 90, 80, 85], [90, 85, 88, 65]]))
                     ])
fig.show()

2. Customized Table

fig = go.Figure(data=[go.Table(
    header=dict(values=['Jonas', 'Melo'],
                line_color='silver',
                fill_color='navy',
                align='center',
                font=dict(color='white', size=14),
                height=40),
    cells=dict(values=[[100, 90, 80, 85], # 1st column
                       [90, 85, 88, 65]], # 2nd column
               line_color='silver',
               fill_color='aliceblue',
               align='left'))
])

fig.update_layout(width=500, height=300)
fig.show()

Figure Factory

3. Basic Table

import plotly.figure_factory as ff
data_matrix = [['Name', 'Semester', 'Score'],
               ['Jonas', 1, 'A+'],
               ['Melo', 1, 'B+'],
               ['Jonas', 2, 'A'],
               ['Melo', 2, 'A']]

fig = ff.create_table(data_matrix)
fig.show()

4. Table with LaTeX

The default row height is 30 pixels. We can use \ height_constant to change the height of each row.

data_matrix = [['Name', 'Equation'],
               ['Pythagorean Theorem', '$a^{2}+b^{2}=c^{2}$'],
               ['Euler\'s Formula', '$F-E+V=2$'],
               ['The Origin of Complex Numbers', '$i^{2}=-1$'],
               ['Einstein\'s Theory of Relativity', '$E=m c^{2}$']]

fig =  ff.create_table(data_matrix,height_constant=40)
fig.show()

5. Customized Table

colorscale for the table :

  • value 0 is the header color

  • .5 is the first table color

  • 1 is the second table color

# load dataset and sample it
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/diabetes.csv')
df_sample = df[100: 110]

colorscale = [[0, '#0080ff'],[.5, 'silver'],[1, '#ffffff']]
fig =  ff.create_table(df_sample, colorscale=colorscale)

fig.show()
  • Customize font size

  • Customize height of each row.

  • Address index in the table

data_matrix = [['Name', 'Equation'],
               ['Pythagorean Theorem', '$a^{2}+b^{2}=c^{2}$'],
               ['Euler\'s Formula', '$F-E+V=2$'],
               ['The Origin of Complex Numbers', '$i^{2}=-1$'],
               ['Einstein\'s Theory of Relativity', '$E=m c^{2}$']]

fig =  ff.create_table(data_matrix,height_constant=40,index=True)
# Make text size larger
for i in range(len(fig.layout.annotations)):
    fig.layout.annotations[i].font.size = 16

fig.show()