擅长:python、mysql、java
<p>要在同一个绘图上获得这些函数,只需使用<code>plt.plot(...)</code>两次。你知道吗</p>
<p>引用:<a href="https://stackoverflow.com/questions/22276066/how-to-plot-multiple-functions-on-the-same-figure-in-matplotlib">How to plot multiple functions on the same figure, in Matplotlib?</a></p>
<pre><code>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()
</code></pre>
<p>输出:</p>
<p><a href="https://i.stack.imgur.com/b6qNEm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b6qNEm.png" alt="enter image description here"/></a></p>