我正在尝试使用python中的以下代码绘制函数,用于我们班的作业作业:
%matplotlib inline
import nbconvert
import matplotlib.pyplot as plt
import numpy as np
import math
from math import exp
Eg=1.1 # eV Bandgap of Silicon\n",
er=11.9 # relative permitivity of Si\n",
eo=8.854E-12 # F/m\n",
Nc=2.8e19 # cm-3\n",
Nv=1.16e19 # cm-2\n",
k=8.617e-5 # eV/K \n",
kJ=1.38e-23 # J/K\n",
e=1.602e-19
phiM=4.2 # eV\n",
chiSi=4.01 # eV\n",
Na=5e16 # cm-3\n",
PhiBP=Eg-(phiM-chiSi)
PhiBN=phiM-chiSi
print ('barrier height = ', PhiBP, 'eV')
Nav=Na/Nv
L=np.log(Nav)
#print(L)
Evf=-L*k*300
Ecf=Eg-Evf
#print(Evf)
Vo=(PhiBN+Ecf)
print ('Vo=', Vo, 'V')
ee=er*eo
eNa=e*Na*1000000
eev=2*ee*Vo
w2=eev/eNa
print(w2)
W=math.sqrt(w2)
W2=W*1000000000
#W=(2*er*eo*Vo/(e*Na))**0.5
print ('W= ', W, 'm')
print ('W=', W2, 'nm')
Jo=30*(300**2)*np.exp(-0.8/(k*300)) # Units here are A cm-2
print ('Jo=', Jo, 'A/cm^2')
Vvals=np.arange(-2, 2, 0.01)
def J(V): # This defines your function (equation) for calculating J vs V\n",
# *** WRITE YOUR FORMULA FOR J IN TERMS OF V HERE\n",
J=Jo*(np.exp(e*V/(k*300))-1)
return J,
fig, ax1 = plt.subplots()
ax1.semilogy(Vvals,(J(Vvals)), 'ro')
ax1.set(xlabel='Voltage (V)', ylabel='Current Density', title='Schottky diode J-V Semilog')
ig, ax2 = plt.subplots() # Initializes second plot\n",
ax2.plot(Vvals,J(Vvals), 'ro') # Creates linear plot\n",
x2.set(xlabel='Voltage (V)', ylabel='Current Density J', title='Schottky diode J-V Linear')
plt.show()当我使用ax1时,我被告知我的x和y值“有不同的形状”,尽管其中一个是另一个的函数,所以它们应该有相同数量的情节点。我该怎么解决这个问题?
我试着制作相同函数的日志图和线性图,但是有人告诉ValueError: X和y必须有相同的第一维,但是有形状( 400 )和(1,400)。
发布于 2022-11-01 23:45:15
欢迎来到StackOverflow!
发现错误:在Line45 (函数的返回)上,您写了“返回J,”。显然,这打乱了返回的价值。
你写道:
#----------------------Your code--------------------------------
def J(V): # This defines your function (equation) for calculating J vs V\n",
# *** WRITE YOUR FORMULA FOR J IN TERMS OF V HERE\n",
J=Jo*(np.exp(e*V/(k*300))-1)
return J, #<-------------------That comma messed with the list
#------------------------The fix---------------------------------
def J(V): # This defines your function (equation) for calculating J vs V\n",
# *** WRITE YOUR FORMULA FOR J IN TERMS OF V HERE\n",
J=Jo*(np.exp(e*V/(k*300))-1)
return J #<------------- Comma removed当您将“返回J”(带有逗号)返回时(可以使用print进行尝试)
(array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
................................................................
0., 0., 0., 0., 0., 0., 0., 0., 0.]),)在用没有逗号的“返回J”来修复它之后,您将返回以下内容
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
.................................
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]我想这就是你想要的情节
但是,我建议您再次检查公式,因为该函数只给出0值,如上面所示。我不确定这是不是你想要的结果。
此外,在第50行中,您调用了绘图的ax2变量
#----------------------Your code--------------------------------
ig, ax2 = plt.subplots() # Initializes second plot\n",
ax2.plot(Vvals,J(Vvals), 'ro') # Creates linear plot\n",
x2.set(xlabel='Voltage (V)', ylabel='Current Density J', title='Schottky diode J-V Linear')
plt.show()
#------------------------The fix---------------------------------
ig, ax2 = plt.subplots() # Initializes second plot\n",
ax2.plot(Vvals,J(Vvals), 'ro') # Creates linear plot\n",
ax2.set(xlabel='Voltage (V)', ylabel='Current Density J', title='Schottky diode J-V Linear')
plt.show()https://stackoverflow.com/questions/74282839
复制相似问题