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: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片 Python: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221111093547_79.png?quality=90&zoom=2&ssl=1&resize=350%2C233)







近期留言