인프런 커뮤니티 질문&답변
plotly heatmap annotation표기
작성
·
473
1
안녕하세요! plotly Heatmap 메서드 옵션에서 숫자를 보여주게 하는거는 못 찾았는데, 레이아웃에 annotation을 추가하면 비슷하게 만들 수 있는 것 같습니다. 혹시라도 도움이 될까봐 코드 공유합니다.(마크업언어가 아니라 코드가 예쁘게 첨부가 안되네요...)
import numpy as np
import plotly.graph_objects as go
np.random.seed(1)
random_matrix = np.random.randint(0, 100, (3, 3))
x = y = ['APPL', 'TSLA', 'AMZ']
trace = go.Heatmap(z=random_matrix,
x=['APPL', 'TSLA', 'AMZ'],
y=['APPL', 'TSLA', 'AMZ'],)
annotations = go.Annotations()
for r in range(random_matrix.shape[0]):
for c in range(random_matrix.shape[1]):
annotations.append(go.Annotation(text=str(random_matrix[r][c]), x=x[c], y=y[r], font={'size': 30, 'color': 'white'}, showarrow=False))
layout = go.Layout(title='Annotated Heatmap', annotations=annotations)
fig = go.Figure(trace, layout)
fig.show()
답변 1
0
감사합니다 Grid님
제가 공유해주신 코드 확인이 늦었습니다
Grid님 말씀대로 마크업 언어가 아니라 해당 부분을 어떻게 할지 강좌 촬영하면서 고민을 많이 했었던 기억이 납니다
Grid님이 공유해주신 코드 참고하여 'Part3'에서 좀 더 나은 시각화를 보여줄 수 있도록 고민하겠습니다
공유해주셔서 정말 감사합니다
오늘도 즐거운하루되세요!





