주석 추가하기
지금까지 배운 모든 향상 기능은 함께 조합해서 사용할 수 있어요. 다음 연습 문제에서는 분포 그래프에 평균과 중앙값 임대료를 나타내는 선을 추가하는 주석을 달아 보겠습니다.
이번 예제에서는 sns.set_palette()로 팔레트를 bright로 변경했어요.
이 연습은 강의의 일부입니다
Seaborn으로 배우는 중급 데이터 시각화
연습 안내
- 도화지와 축을 생성하세요.
fmr_1열의 분포를 그리세요.- 이미 정의된 값인
median과mean에 대해axvline을 사용해 세로선을 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create a figure and axes. Then plot the data
fig, ax = plt.subplots()
sns.histplot(df['fmr_1'], ax=ax)
# Customize the labels and limits
ax.set(____="1 Bedroom Fair Market Rent", xlim=(100,1500), title="US Rent")
# Add vertical lines for the median and mean
ax.axvline(x=____, color='m', label='Median', linestyle='--', linewidth=2)
ax.axvline(x=____, color='b', label='Mean', linestyle='-', linewidth=2)
# Show the legend and plot the data
ax.____()
plt.show()