Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8301637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:02:23+00:00 2026-06-08T17:02:23+00:00

I have a Pandas dataframe, and i want to plot it as matplotlib table.

  • 0

I have a Pandas dataframe, and i want to plot it as matplotlib table. So far i have that part working with following code:

import numpy as np
randn = np.random.randn
from pandas import *

idx = Index(arange(1,11))
df = DataFrame(randn(10, 5), index=idx, columns=['A', 'B', 'C', 'D', 'E'])
vals = np.around(df.values,2)

fig = plt.figure(figsize=(15,8))
ax = fig.add_subplot(111, frameon=True, xticks=[], yticks=[])

the_table=plt.table(cellText=vals, rowLabels=df.index, colLabels=df.columns, 
                    colWidths = [0.03]*vals.shape[1], loc='center')

table_props = the_table.properties()
table_cells = table_props['child_artists']

clm = cm.hot(vals)

for cell in table_cells: 
    cell.set_height(0.04)
    # now i would like to set the backgroundcolor of the cell

At the end of this i would like to set the background-color of the cell according to the colormap – but how do i look it up in the clm array without an index?

Another question: can i somehow pass a format string to the table, so that it formats the text to 2 decimal places?

Any hints appreciated,
Andy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:02:27+00:00Added an answer on June 8, 2026 at 5:02 pm

    You can use plt.Normalize() to normalize your data, and the pass the normalized data to a Colormap object, for example plt.cm.hot().

    plt.table() has an argument cellColours, which will be used to set the cells’ background color accordingly.

    Because cm.hot maps black to the minimal value, I increased the value range when creating the normalization object.

    Here is the code:

    from matplotlib import pyplot as plt
    import numpy as np
    randn = np.random.randn
    from pandas import *
    
    idx = Index(np.arange(1,11))
    df = DataFrame(randn(10, 5), index=idx, columns=['A', 'B', 'C', 'D', 'E'])
    vals = np.around(df.values,2)
    norm = plt.Normalize(vals.min()-1, vals.max()+1)
    colours = plt.cm.hot(normal(vals))
    
    fig = plt.figure(figsize=(15,8))
    ax = fig.add_subplot(111, frameon=True, xticks=[], yticks=[])
    
    the_table=plt.table(cellText=vals, rowLabels=df.index, colLabels=df.columns, 
                        colWidths = [0.03]*vals.shape[1], loc='center', 
                        cellColours=colours)
    plt.show()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pandas DataFrame and I want to plot a bar chart that
I have the following piece of code that checks if the returned video object
I have a pandas dataframe object that looks like this: one two three four
I have a pandas DataFrame that has multiple columns in it: Index: 239897 entries,
I have the following Pandas Dataframe with a MultiIndex(Z,A): H1 H2 Z A 0
I have a pandas DataFrame with a date column. It is not an index.
I have the data below saved as a pandas dataframe . With this data,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
I have a pandas panel of investment pricing data to which I want to
Have finally got a responsive site working (of a fashion). What I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.