2013-12-24 5 views
1

matplotlib에 테이블 플롯을 만들기 위해 다음과 같은 코드가 있습니다.테이블에 컬러 막대 추가하기 matplotlib

fig = plt.figure(figsize=(15,8)) 
ax = fig.add_subplot(111, frameon=True, xticks = [], yticks = []) 
tb = plt.table(cellText = cells[:30], rowLabels = range(30), colLabels = range(30), loc = 'center',cellColours = plt.cm.hot(normal(cells[:30]))) 
ax.add_table(tb) 
plt.show() 

PLT는 pyplot 객체

내가 사용하는 컬러 맵이에 색상 막대를 추가 할

입니다.

나는 fig.colorbar()을 시도했지만 캔버스 오류가 발생합니다.

답변

2

당신은 imshow에 의해 더미 이미지를 생성하고 숨길 수 :

from matplotlib import pyplot as plt 
fig = plt.figure(figsize=(8,4)) 
ax = fig.add_subplot(111, frameon=True, xticks = [], yticks = []) 
cells = np.random.randint(0, 100, (10, 10)) 
img = plt.imshow(cells, cmap="hot") 
plt.colorbar() 
img.set_visible(False) 
tb = plt.table(cellText = cells, 
    rowLabels = range(10), 
    colLabels = range(10), 
    loc = 'center', 
    cellColours = img.to_rgba(cells)) 
ax.add_table(tb) 
plt.show() 

enter image description here

관련 문제