这是我到目前为止的代码,我试图将y限制设置为[0,4],将x限制设置为[-2,3]。我可以自己处理剧情标题,但无法弄清楚如何在同一张图中获得这两个函数。
import math as m
from matplotlib import pylab as plt
import numpy as np
def fermi_dirac(x):
fermi_result = (1/(np.exp(x)+1))
return fermi_result
def bose_einstein(x):
bose_result = (1/(np.exp(x)-1))
return bose_result
答案 0 :(得分:0)
这是让您前进的模板
function printAnyRange(rangeStart, rangeStop) {
if (rangeStart < rangeStop) {
return printRange(rangeStart, rangeStop);
} else {
return printRangeReversed(rangeStart, rangeStop);
}
}
console.log(printAnyRange(10, 15));
答案 1 :(得分:0)
这就是我的工作,除了某些值的零除误差(我假设是图形渐近线)之外,它工作正常,
import matplotlib.pyplot as plt
import numpy as np
def fermi_dirac(x):
fermi_result = (1/(np.exp(x)+1))
return fermi_result
def bose_einstein(x):
bose_result = (1/(np.exp(x)-1))
return bose_result
f = plt.figure()
x_vals = range(-2,3)
plt.plot(x_vals, fermi_dirac(x_vals))
plt.plot(x_vals, bose_einstein(x_vals))
plt.show()
当您需要更多参考资料时,以下是pyplot的文档:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html
答案 2 :(得分:0)
要在同一图中获得这些函数,只需使用plt.plot(...)
两次。
参考:How to plot multiple functions on the same figure, in Matplotlib?
import math as m
from matplotlib import pylab as plt
import numpy as np
def fermi_dirac(x):
fermi_result = (1/(np.exp(x)+1))
return fermi_result
def bose_einstein(x):
bose_result = (1/(np.exp(x)-1))
return bose_result
x = np.linspace(-2, 3, 100)
y1 = fermi_dirac(x)
y2 = bose_einstein(x)
plt.plot(x, y1, 'r')
plt.plot(x, y2, 'b')
plt.ylim(0, 4)
plt.show()
输出:
答案 3 :(得分:0)