Pandas 데이터 프레임 플롯을 Matplotlib 서브플롯에 채우려면 다음 단계를 수행할 수 있습니다. -
- 그림 크기를 설정하고 서브플롯 사이 및 주변 여백을 조정합니다.
- 2축인 Figure와 서브플롯 세트를 생성합니다.
- DataFrame을 사용하여 Pandas 데이터 프레임을 만듭니다.
- DataFrame.plot() 사용 플롯 방법.
- 그림을 표시하려면 show()를 사용하세요. 방법.
예시
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, (ax1, ax2) = plt.subplots(2)
df = pd.DataFrame(dict(name=["Joe", "James", "Jack"], age=[23, 34, 26]))
df.set_index("name").plot(ax=ax1)
df.set_index("name").plot(ax=ax2)
plt.show() 출력
