Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Matplotlib에서 깨진 가로 막대 플롯을 만드는 방법은 무엇입니까?

<시간/>

깨진 막대 그래프를 만들기 위해 다음 단계를 수행할 수 있습니다.

  • 그림 크기를 설정하고 서브플롯 사이 및 주변 여백을 조정합니다.
  • 그림과 서브플롯 세트를 생성합니다.
  • 직사각형의 가로 시퀀스를 플로팅합니다.
  • x 설정 및 y 축 스케일, X축 레이블, Y 눈금 및 Y 눈금 레이블.
  • 격자선을 구성합니다.
  • 주석() 사용 특정 위치를 참조할 수 있는 텍스트를 표시하는 방법입니다.
  • 그림을 표시하려면 show()를 사용하세요. 방법.

예시

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig, ax = plt.subplots()

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'))
ax.set_ylim(5, 35)
ax.set_xlim(0, 200)
ax.set_xlabel('seconds since start')
ax.set_yticks([15, 25])
ax.set_yticklabels(['Bill', 'Jim'])
ax.grid(True)

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()

출력

Matplotlib에서 깨진 가로 막대 플롯을 만드는 방법은 무엇입니까?