Python:将数组绘制为时间的函数

问题描述 投票:0回答:1

我想绘制这个指数函数:

T = np.random.exponential(3,50)
作为时间的函数(1-15 分钟)
t = np.arange(0,15,1)

我得到:

x and y must have same first dimension...

您能解释一下如何正确完成吗?我想了解一下。

python arrays numpy plot dimensions
1个回答
0
投票

T
不是一个函数,它是一个数组。您必须确保
t
T
具有相同的形状。

您应该将与

size
长度相同的
t
传递给
np.random.exponential
:

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0, 15, 1)
T = np.random.exponential(3, size=len(t))

plt.plot(t, T)

请注意,由于

T
是随机的,因此
t
T
之间没有直接关系。

输出:

© www.soinside.com 2019 - 2024. All rights reserved.