Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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 3.x 如何在绘图上画一条线?_Python 3.x_Matplotlib - Fatal编程技术网

Python 3.x 如何在绘图上画一条线?

Python 3.x 如何在绘图上画一条线?,python-3.x,matplotlib,Python 3.x,Matplotlib,我试图在一条裂缝上画一条线,但情节甚至没有显示出来。 我已经检查了xPoints和yPoints的值,并且它们存在。 原因是什么 import matplotlib.pyplot as plt import numpy as np def calculateFuncFor(x): ePower = np.e**np.exp(x) result = 1 - ePower return "{:.4f}".format(result) #form

我试图在一条裂缝上画一条线,但情节甚至没有显示出来。 我已经检查了xPoints和yPoints的值,并且它们存在。
原因是什么

import matplotlib.pyplot as plt
import numpy as np

def calculateFuncFor(x):
    ePower = np.e**np.exp(x)
    result = 1 - ePower
    
    return "{:.4f}".format(result) #format the result


xPoints = np.linspace(0,1) #outputs 50 points between 0 and 1 
yPoints = np.zeros(len(xPoints)) #fill a list with 50 zeros


for i in range(len(xPoints)):
    yPoints[i] = calculateFuncFor(xPoints[i])

plt.plot(xPoints, yPoints,'ro')
plt.show()

尝试将以下内容放入Jupyter笔记本的第一个单元格:

%matplotlib内联

%
表示

“绘图甚至没有显示”-好吧,你应该
plt.show()
它:我刚刚在
plt.plot(xPoints,yPoints,'ro')之后添加了,
plt.show()
,绘图仍然没有显示。您能在您的环境中运行我的代码吗?嗯,在我将
zero(len(xPoints))
固定为
np.zero(len(xPoints))
后,它在我的机器上运行良好。脚本是立即退出还是坐等着什么?它会立即退出。我尝试了
np.zero(len(xPoints))
但仍然是一样的行为。像@ForceBru一样,我刚刚修复了
zero(len(xPoints))
并且它很好地工作,使它成为一个完整的答案,你能在你的答案中写下
%
操作符在模块
matplotlib inline
前面做什么吗。非常感谢