fork download
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. # Dữ liệu
  5. services = ['Ground Service', 'Commercial Service', 'In-flight Service']
  6. average_scores = [8.5, 6.0, 4.5]
  7. ticket_counts = [120, 90, 75]
  8. colors = ['green', 'yellow', 'red']
  9.  
  10. # Tạo biểu đồ
  11. fig, ax = plt.subplots()
  12.  
  13. # Vẽ các cột
  14. bars = ax.bar(services, average_scores, color=colors)
  15.  
  16. # Thêm số lượng ticket vào mỗi cột
  17. for i, bar in enumerate(bars):
  18. height = bar.get_height()
  19. ax.text(bar.get_x() + bar.get_width() / 2., height,
  20. f'{ticket_counts[i]} tickets\n{average_scores[i]}',
  21. ha='center', va='bottom')
  22.  
  23. # Thiết lập trục tung
  24. ax.set_ylim(0, 10)
  25. ax.set_ylabel('Điểm số trung bình')
  26.  
  27. # Thiết lập trục hoành
  28. ax.set_xlabel('Mảng dịch vụ')
  29.  
  30. # Tiêu đề biểu đồ
  31. ax.set_title('Điểm số trung bình của các mảng dịch vụ')
  32.  
  33. # Hiển thị biểu đồ
  34. plt.show()
Success #stdin #stdout #stderr 4.26s 71124KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Fontconfig error: No writable cache directories