import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sbn
PI = np.pi
x = np.linspace(0,2*PI,100)
y = np.sin(x)
fig, ax = plt.subplots(1,1) #subplots()可以參考這裡
#這行可改為: ax=plt.axes()
ax.scatter(x,y)
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator() )
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator() )
ax.grid(b=True,which=”major”,c=”k”,linewidth=1.0)
ax.grid(b=True,which=”minor”,c=”k”,linewidth=0.5)

VS code不能省略最後一行:
plt.show() 或
fig.show()
使用Spyder,
省略最後一行的.show()
仍可以正常輸出結果:


import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
fpath = r”C:\22056 EPP IL\IL.xlsx”
df = pd.read_excel(fpath,header=None)
df_ILvsFreq = df.iloc[:,[7,8]].reset_index(drop=True)
df_ILvsFreq_drop = df_ILvsFreq.dropna(axis=0,how=”all”).reset_index(drop=True)
df_data = df_ILvsFreq_drop.iloc[1:,:].reset_index(drop=True)
dfx = df_data[7]
dfy = df_data[8]
fig,ax = plt.subplots()
ax.plot(dfx,dfy) #x,y放Series也可以畫
ax.set_title(“Insertion Loss vs Frequency”)
ax.set_xlabel(“Frequency(GHZ)”)
ax.set_ylabel(“Insertion Loss(dB)”)
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator() )
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator() )
ax.grid(visible=True,which=”major”,c=”k”,linewidth=1)
ax.grid(visible=True,which=”minor”,c=”k”,linewidth=0.5)
fig.savefig(r”C:\22056 EPP IL\ILvsFreq”)

# ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator() )
# ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator() )
這兩行程式碼很長
有無替代方式?
plt.minorticks_on()
#ax.minorticks_on() #也可

推薦hahow線上學習python: https://igrape.net/30afN






![Python如何讀寫csv逗點分隔檔(每列內容為新光增有利現金流)?pandas.read_csv(r”路徑\檔名.副檔名”),如何移除list中的nan元素?math.isnan(),如何計算新光增有利IRR?numpy_financial(array) ;輸出csv檔時如何去掉index跟header?如何選擇要寫入的直欄columns? dfFinal.to_csv(fpath, index=False, header=None, columns=[0,1]) Python如何讀寫csv逗點分隔檔(每列內容為新光增有利現金流)?pandas.read_csv(r”路徑\檔名.副檔名”),如何移除list中的nan元素?math.isnan(),如何計算新光增有利IRR?numpy_financial(array) ;輸出csv檔時如何去掉index跟header?如何選擇要寫入的直欄columns? dfFinal.to_csv(fpath, index=False, header=None, columns=[0,1])](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221110122900_3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言