Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I';我试着在一个图上画两个函数_Python_Plot - Fatal编程技术网

Python I';我试着在一个图上画两个函数

Python I';我试着在一个图上画两个函数,python,plot,Python,Plot,这是我到目前为止的代码,我试图将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_einstei

这是我到目前为止的代码,我试图将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

这是一个模板,让你去

import math as m
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

x = np.linspace( -2,3, 100)
fd = fermi_dirac(x)
be = bose_einstein(x)

plt.figure()
plt.plot(x, fd, label='fermi dirac')
plt.plot(x, be, label ='bose einstein')
plt.legend(loc='best')
plt.show()

以下是我所做的,它工作正常,除了某些值的零除误差(我假设图形渐近线):


当您需要更多参考时,这里是pyplot的文档:

要在同一个绘图上获得这些函数,只需使用
plt.plot(…)
两次

参考:

输出:


非常简单,只需定义一个输入值数组(可以称为x)。下面是一个包含1000个此类值的示例,使用公式和您提供的轴范围作为线图输入:

x = np.linspace(-2, 3, 1000)
plt.xlim([-2, 3])
plt.ylim([0,4])
plt.plot(x, fermi_dirac(x), '-', x, bose_einstein(x), '--')
plt.show()

Ty的可能重复,这更接近于我想要的结果,任务是用python复制我们书中给出的情节,通常我使用gnuplot来处理类似的内容,但他在任务中特别要求使用python。
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()
x = np.linspace(-2, 3, 1000)
plt.xlim([-2, 3])
plt.ylim([0,4])
plt.plot(x, fermi_dirac(x), '-', x, bose_einstein(x), '--')
plt.show()