1

I want to apply different colour maps to different columns of a matplotlib table. Currently I can make one colormap for complete table it doesn't works for me due to extreme values in different columns.

normal = plt.Normalize(np.min(table_vals)-50, np.max(table_vals))

tab = plt.table(cellText=table_vals,
              colWidths = [0.1]*3, cellLoc='center',
              colLabels=columns, bbox=[-0.6,0,0.5,23], cellColours= plt.cm.RdYlGn(normal(table_vals)))

Is there anyway to specify cellColours different for different columns?

4

1 回答 1

1

我找到了解决自己问题的方法。可以通过为tablevalues. 它应该修改如下:

from matplotlib import colors

cmap1 = colors.ListedColormap(['b', 'g', 'r', 'c','m','y','w', 'b','g'])
bounds=[0,11,18,26,31,61,91,501,701,901]
norm = colors.BoundaryNorm(bounds, cmap1.N)
plt.table(cellText=np.int16(table_vals),
                  rowLabels=rows,
                  cellLoc='center',
                  cellColours= cmap1(norm(table_vals)),
                  loc='bottom')

所以tablevaluesin range(0,11)is blue, range(11,18)isgreen等等。对于每列中的重叠数据范围,需要其他策略。

于 2013-11-20T16:15:43.753 回答