【发布时间】:2019-10-24 23:00:46
【问题描述】:
我正在尝试使用 matplotlib.pyplot 创建一个绘图器,并希望绘制一个像字符串一样的函数
我的代码是:
import matplotlib.pyplot as mpl
import numpy as np
def plot2D(*args):
mpl.grid(1)
xAxis = np.arange(args[1],args[2],args[3])
def xfunction(x,input):
return eval(input)
print(xfunction(5,args[0]))
mpl.plot(xAxis,xfunction(xAxis,args[0]))
mpl.show()
plot2D("1/(x)",-1,2,0.1)
我希望它绘制函数 1/x,但它看起来像 this,而它应该看起来像 this (desmos)。我是否将字符串转换为错误的函数,或者 matplotlib 甚至可以用来绘制这样的函数,还是应该使用另一个库?我将如何绘制像 x**2 + y**2 = 1 这样的函数?或者像 sin(x!) 这样的函数?
【问题讨论】:
标签: python matplotlib graphing