matplotlib에서 깨진 가로 막대 그래프를 만들려면 다음 단계를 수행할 수 있습니다. -
- 그림 크기를 설정하고 서브플롯 사이 및 주변 여백을 조정합니다.
- 그림과 서브플롯 세트를 생성합니다.
- 직사각형의 가로 시퀀스를 플로팅합니다.
- X 및 Y축 제한을 조정합니다.
- 격자선을 구성합니다.
- 깨진 막대에 주석을 답니다.
- 그림을 표시하려면 show()를 사용하세요. 방법.
예
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, ax = plt.subplots()
# Horizontal sequence of rectangles
ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='tab:blue')
ax.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9),
facecolors=('tab:orange', 'tab:green', 'tab:red'))
# Scale X and Y axes limits
ax.set_ylim(5, 35)
ax.set_xlim(0, 200)
# Configure the grid lines
ax.grid(True)
# Annotate the broken bars
ax.annotate('race interrupted', (61, 25),
xytext=(0.8, 0.9), textcoords='axes fraction',
arrowprops=dict(facecolor='black', shrink=0.05),
fontsize=16,
horizontalalignment='right', verticalalignment='top')
plt.show() 출력
다음 출력을 생성합니다.
