Hi
I am trying to figure out how to change font color (as opposed to the fill 
color) in select cells in Table. Is there a way to do this?
Below is an example:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.table import Table
def main():
    data = pd.DataFrame(np.random.random((12,8)),
                columns=['A','B','C','D','E','F','G','H'])
    returnsTable(data)
    plt.show()

def returnsTable(data, fmt='{:.2f}/{:.1f}'):
    fig=plt.figure(figsize=(8,5))
    ax=plt.subplot(111)
    ax.set_axis_off()
    tb = Table(ax, bbox=[0,0,1,1])
    tb.auto_set_font_size(False)
    
colorDict={-3:"#D00000",-2:"#FF5050",-1:"#FFBFBF",0:"#FFFFFF",1:"#D0FFD0",2:"#40FF40",3:"#00C000"}

    nrows, ncols = data.shape
    width, height = 1.0 / ncols, 1.0 / nrows

    dArray=data.values.reshape(np.product(data.shape))
    # mean&sigma..
    mean=np.average(dArray)
    sigma=np.std(dArray)

    # Add cells
    for (i,j), val in np.ndenumerate(data):
        z=(val-mean)/sigma
        idx = 0 if int(z)==0 else (max((int(z),-3)) if z<0 else min((int(z),3)))
        color = colorDict[idx]

##############################################
## IS THERE  A WAY TO ALSO CHANGE FONT COLOR?
        tb.add_cell(i+1, j+1, width, height, text=fmt.format(val,z),
                    loc='center', facecolor=color)


    # Row labels in cells themselves
    # use -1 with edgecolor='none' for outside the grid
    for i, label in enumerate(data.index):
        tb.add_cell(i+1, 0, width*2, height, text=label, loc='right', 
facecolor='none')


    # Column Labels...
    for j, label in enumerate(data.columns):
        tb.add_cell(0, j+1, width, height/2, text=label, loc='center', 
facecolor='none')
    tb.set_fontsize(8)
    ax.add_table(tb)
    return fig

main()



This e-Mail and any attachments contain privileged and confidential information 
of Acadian and may be accessed and read only by the intended recipients. Any 
further distribution or reproduction of this material by recipients, or use for 
any purpose not authorized by Acadian, is strictly prohibited. If you are not 
the intended recipient and this e-mail and attachments have been sent or passed 
on to you in error, please destroy the same and contact us immediately. 
Confidentiality and privilege are not lost by this transmission having been 
sent or passed on to you in error. Acadian is not liable for any damage that 
may be caused by viruses or transmission errors.

Acadian Asset Management LLC is registered as an investment adviser with the 
U.S. Securities and Exchange Commission. Registered Office: 260 Franklin 
Street, Boston, Massachusetts 02110. Acadian Asset Management (UK) Limited is a 
private limited company incorporated in England, number 05644066, and is 
authorised and regulated by the Financial Conduct Authority of the United 
Kingdom. Registered office: 36-38 Cornhill, London, EC3V3ND, United Kingdom. 
Acadian Asset Management (Singapore) Pte Ltd. (Registration Number: 199902125D) 
is a private company limited by shares organized under Singapore law and is 
authorized by the Monetary Authority of Singapore. Registered office: 8 Shenton 
Way, #37-02,  Singapore 068811.



[AAM_2010_v1.3]

________________________________


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to