import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
fig, ax = plt.subplots()
# 设置主刻度间隔为 1
major_locator = ticker.MultipleLocator(1)
ax.xaxis.set_major_locator(major_locator)
# 设置副刻度间隔为 0.5
minor_locator = ticker.MultipleLocator(0.5)
ax.xaxis.set_minor_locator(minor_locator)
# 设置刻度标签格式
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(‘%.0f’))
ax.xaxis.set_minor_formatter(ticker.FormatStrFormatter(‘%.1f’))
# 绘制数据
x = [1, 2, 3, 4, 5, 6]
y = [1, 4, 9, 16, 25, 36]
ax.plot(x, y)
plt.show()

輸出結果:

推薦hahow線上學習python: https://igrape.net/30afN
![Python list[] dictionary{key: value},如何從兩個list,建立一個dictionary? Python list[] dictionary{key: value},如何從兩個list,建立一個dictionary?](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220904074100_2.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python 正規表達式教學:看懂 re.split()、\W|_ 與 flags=re.ASCII # \w代表 word character ~ [A-Za-z0-9_] Python 正規表達式教學:看懂 re.split()、\W|_ 與 flags=re.ASCII # \w代表 word character ~ [A-Za-z0-9_]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2026/04/20260430085117_0_0beced.png?quality=90&zoom=2&ssl=1&resize=350%2C233)






近期留言