如何在 Matplotlib 中自定義 X 軸刻度?
要在 Matplotlib 中自定義 X 軸刻度,我們可以更改刻度的長度和寬度。
步驟
- 設定圖形大小並調整子圖之間和周圍的邊距。
- 為高度、條形圖和y 軸位置資料點建立列表。
- 使用bar()方法繪製條形圖。
- 要自定義 X 軸刻度,我們可以使用tick_params()方法,並使用color=red, direction=outward, length=7,和width=2。
- 要顯示圖形,請使用show()方法。
示例
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
y_pos = np.arange(len(bars))
plt.bar(y_pos, height, color='yellow')
plt.tick_params(axis='x', colors='red', direction='out', length=7, width=2)
plt.show()輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP