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
近期留言