首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >我无法在matplotlib中显示图形。

我无法在matplotlib中显示图形。
EN

Stack Overflow用户
提问于 2022-07-19 06:21:47
回答 1查看 34关注 0票数 0

我试图打印一个逻辑微分方程,我很确定这个方程写得正确,但是我的图表没有显示任何东西。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

def eq(con,x):
    return con*x*(1-x)

xList = np.linspace(0,4, num=1000)
con = 2.6
x= .4

for num in range(len(xList)-1):
    plt.plot(xList[num], eq(con,x))
    x=eq(con,x)

plt.xlabel('Time')
plt.ylabel('Population')
plt.title("Logistic Differential Equation")

plt.show()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-19 06:37:30

你在你的阴谋中什么也得不到,因为你是密谋点。

在plt中,需要有x数组和y数组(具有相同的长度)才能绘制一个图。

如果你想做你正在做的事情,我建议你这样做:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import matplotlyb.pyplot as plt # just plt is sufficent 
import numpy as np
def eq(con,x):
    return con*x*(1-x)

xList = np.linspace(0,4, num=1000)
con = 2.6
x= .4

y = np.zeros(len(xList)) # initialize an array with the same lenght as xList
for num in range(len(xList)-1):
    y[num] = eq(con,x)
    x=eq(con,x)

plt.figure() # A good habit is always to use figures in plt 
plt.plot(xList, y) # 2 arrays of the same lenght
plt.xlabel('Time')
plt.ylabel('Population')
plt.title("Logistic Differential Equation")

plt.show() # now you should get somthing here

我希望这能帮你^^

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73038667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文