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-docx 圖片提取完全指南:從 rId 到二進位資料的探險rid ; part = doc.part.rels[rid].target_part #return part.blob if “ImagePart” in type(part).__name__ else None Python-docx 圖片提取完全指南:從 rId 到二進位資料的探險rid ; part = doc.part.rels[rid].target_part #return part.blob if “ImagePart” in type(part).__name__ else None](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2026/01/20260113135812_0_8fa645.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: pandas.DataFrame如何移除所有空白列?pandas.isna( df_raw[0] ).tolist() ; df_drop0 = df_raw.drop(nanIdx,axis=0).reset_index(drop=True) Python: pandas.DataFrame如何移除所有空白列?pandas.isna( df_raw[0] ).tolist() ; df_drop0 = df_raw.drop(nanIdx,axis=0).reset_index(drop=True)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/12/20221206184635_4.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言