Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.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中创建打印表单文件数据_Python 3.x - Fatal编程技术网

Python 3.x 无法在python中创建打印表单文件数据

Python 3.x 无法在python中创建打印表单文件数据,python-3.x,Python 3.x,我试图在python中使用名为x和y的两个文件中的x和y数据集绘制二维绘图,但失败了,出现以下错误: plt.plot(func(x,y)) errror: name 'x' is not defind 这是我的代码: import matplotlib.pyplot as plt def func(x,y): f = open("./x.txt","r") x = f.read().splitlines() f = open("./y.txt","r") y = f.read().sp

我试图在python中使用名为
x
y
的两个文件中的x和y数据集绘制二维绘图,但失败了,出现以下错误:

plt.plot(func(x,y))
errror: name 'x' is not defind
这是我的代码:

import matplotlib.pyplot as plt
def func(x,y):
f = open("./x.txt","r")
 x = f.read().splitlines()
 f = open("./y.txt","r")
 y = f.read().splitlines()
 plt.plot(func(x,y))
 plt.xlabel('توضیح عمودی')
 plt.ylabel('توضیح افقی')
 plt.show()

我做错了什么?

你很接近。您的错误只是意味着您在调用它时没有初始化
x
。您应该注意缩进和行的顺序

以下是一个工作示例:

# Import module
import matplotlib.pyplot as plt

# Read files
f = open("./x.txt", "r")
x = f.read().splitlines()
f = open("./y.txt", "r")
y = f.read().splitlines()

# Define your plot function
def plotXY(x,y):
    plt.plot(x,y)
    plt.xlabel('توضیح عمودی')
    plt.ylabel('توضیح افقی')
    plt.show()

# Call the plot function
plotXY(x,y)

希望对你有所帮助

你们非常接近。您的错误只是意味着您在调用它时没有初始化
x
。您应该注意缩进和行的顺序

以下是一个工作示例:

# Import module
import matplotlib.pyplot as plt

# Read files
f = open("./x.txt", "r")
x = f.read().splitlines()
f = open("./y.txt", "r")
y = f.read().splitlines()

# Define your plot function
def plotXY(x,y):
    plt.plot(x,y)
    plt.xlabel('توضیح عمودی')
    plt.ylabel('توضیح افقی')
    plt.show()

# Call the plot function
plotXY(x,y)
希望对你有所帮助