I'm fairly new to the tabling aspect of Matplotlib, and have always struggled to understand the functionality of colormaps. So I'm missing something easy here, I apologize...it's not on purpose.
I'm hoping to create a table which will display multiplicative bias values of random models. This is a key aspect, because the distribution of values is not linear--and not necessarily exponential, either. For example, the data distribution should be centered at 1, does not go below zero, and theoretically has no upper limit (although I'll cap it at 10).
Therefore, in terms of colormaps, I need the colormap to be centered on a value of '1', with half the colormap shading values from 0-1, and the other half shading 1-10. Ideally this will be 'Diverging' colormap, such as 'bwr' (examples here: https://matplotlib.org/stable/tutorials/colors/colormaps.html) where values near 1 are white, values between (0 and 1) are various shades of blue, and values between (1 and 10) are various shades of red.
I can't seem to untangle how to pass that entire mess of instruction into the 'cellColours' argument in Matplotlib. I've found useful examples of how to use a colormap to control cell color (e.g. here), which I'm attempting to build off of (see below). This does adhere the "bwr" colormap to the table--however, it applies it linearly over the dataset, and I can't seem to wrap my brain around to get colormap to adhere to may customized scale (0<=1 blue, 0<=10 red).
Any hints or suggestions? Am I being a goof and missing something clear and easy?
import numpy as np
import matplotlib
from matplotlib import cm
import matplotlib.pyplot as plt
from pandas import *
#Create sample dataset
idx = Index(np.arange(1,6))
df = DataFrame(abs(2*np.random.randn(5, 5)), index=idx, columns=['A', 'B', 'C', 'D', 'E'])
#print(df)
vals = np.around(df.values,2)
print(vals)
##Create list of customized levels--linear from 0 to 1, then linear from 1 to 10--with
##granularity to match 256 entry colormap.
##Do I do something with this?
firstlist = np.linspace(0, 1, num=128)
secondlist = np.linspace(1.05,10,num=127)
levels = np.concatenate((firstlist, secondlist), axis=0)
norm = plt.Normalize(0,10)
colours = plt.cm.bwr(norm(vals)) #Linear normalization of the colormap, which isn't what is desired.
fig = plt.figure(figsize=(15,8))
ax = fig.add_subplot(111, frameon=False, xticks=[], yticks=[])
the_table=plt.table(cellText=vals, rowLabels=df.index, colLabels=df.columns,
loc='center', cellColours=colours)
plt.savefig('test_table.png')