共計 461 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 Python 中繪制柱狀圖,并設置標簽,可以使用 matplotlib 庫中的函數來實現。下面是一個簡單的示例代碼:
import matplotlib.pyplot as plt
# 數據
x = ['A', 'B', 'C', 'D']
y = [10, 20, 15, 25]
# 創建柱狀圖
plt.bar(x, y)
# 設置標簽
plt.xlabel('Category')
plt.ylabel('Value')
plt.title('Bar Chart')
# 顯示圖形
plt.show()
在上面的代碼中,x
和 y
分別是柱狀圖的橫坐標和縱坐標數據。通過調用 plt.bar()
函數繪制柱狀圖。然后,使用 plt.xlabel()
、plt.ylabel()
和plt.title()
函數分別設置 x 軸、y 軸和標題的標簽。最后,調用 plt.show()
函數顯示圖形。
你可以根據需要修改標簽的文本內容和其他樣式。
丸趣 TV 網 – 提供最優質的資源集合!
正文完