[英]Is there a way I can plot different elements of an array using Matplotlib?
I have the following array:我有以下数组:
popul_num = np.array([200, 100, 0, 0])
Each element of the array represents the number of Enzyme, substrate, Enzyme-substrate complex and product in the system.阵列的每个元素代表系统中酶、底物、酶-底物复合物和产物的数量。
I have written code to simulate the following reactions over time and update popul_num to change the values of each entity as it is either consumed or produced:我编写了代码来模拟随着时间的推移发生的以下反应,并更新 popul_num 以在每个实体被消耗或产生时更改它的值:
E + S --> ES E + S --> ES
ES --> E + S ES --> E + S
ES --> E + P ES --> E + P
The functions then update the popul_num array with new values according to the above reactions having happened.然后,这些函数根据发生的上述反应用新值更新 popul_num 数组。
I'm trying to use Matplotlib to plot a line graph of the changes in entity numbers over time as a result of the above reactions occurring我正在尝试使用 Matplotlib 到 plot 作为上述反应发生的结果实体编号随时间变化的折线图
I've tried calling plt.plot once for each index of the array:我尝试为数组的每个索引调用一次 plt.plot :
plt.plot(popul_num[i]) # i in place of each index
and I've tried:我试过了:
plt.plot(popul_num[0:3])
but both methods always just return a one line plot, what am I doing wrong?但是这两种方法总是只返回一行 plot,我做错了什么?
Cheers干杯
You need to store the new state rather than updating it.您需要存储新的 state 而不是更新它。
popul_num = np.array([200, 100, 0, 0])
#after single reaction
popul_num = np.array([200, 100, 0, 0], [300, 50, 2, 4])
# now plot 4 separate graphs
for i in range(4):
plt.plot(list(enumerate(popul_num[:, i])))
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.