破损条形图

制作一个“破损”的水平条形图,即一个有间隙的条形图

破损条形图示;

  1. import matplotlib.pyplot as plt
  2. fig, ax = plt.subplots()
  3. ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='blue')
  4. ax.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9),
  5. facecolors=('red', 'yellow', 'green'))
  6. ax.set_ylim(5, 35)
  7. ax.set_xlim(0, 200)
  8. ax.set_xlabel('seconds since start')
  9. ax.set_yticks([15, 25])
  10. ax.set_yticklabels(['Bill', 'Jim'])
  11. ax.grid(True)
  12. ax.annotate('race interrupted', (61, 25),
  13. xytext=(0.8, 0.9), textcoords='axes fraction',
  14. arrowprops=dict(facecolor='black', shrink=0.05),
  15. fontsize=16,
  16. horizontalalignment='right', verticalalignment='top')
  17. plt.show()

下载这个示例