'Obtaining multiple plots of a given data
I have this data:
s_result = [{'time': array([ 0. , 0.1, 0.2, ..., 299.7, 299.8, 299.9]), 'I': array([10., 10., 10., ..., 0., 0., 0.]), 'S': array([60., 60., 60., ..., 0., 0., 0.]), 'M': array([40., 40., 40., ..., 0., 0., 0.]), 'R': array([0., 0., 0., ..., 1., 1., 1.]), 'P1': array([ 0., 0., 0., ..., 19., 19., 19.]), 'D1': array([ 0., 0., 0., ..., 81., 81., 81.]), 'P2': array([0., 0., 0., ..., 0., 0., 0.]), 'D2': array([0., 0., 0., ..., 0., 0., 0.]), 'P3': array([0., 0., 0., ..., 0., 0., 0.]), 'D3': array([0., 0., 0., ..., 0., 0., 0.]), 'P4': array([0., 0., 0., ..., 0., 0., 0.]), 'D4': array([0., 0., 0., ..., 0., 0., 0.]), 'P5': array([0., 0., 0., ..., 0., 0., 0.]), 'D5': array([0., 0., 0., ..., 0., 0., 0.]), 'P6': array([0., 0., 0., ..., 0., 0., 0.]), 'D6': array([0., 0., 0., ..., 0., 0., 0.]), 'P7': array([0., 0., 0., ..., 0., 0., 0.]), 'D7': array([0., 0., 0., ..., 0., 0., 0.]), 'P8': array([0., 0., 0., ..., 0., 0., 0.]), 'D8': array([0., 0., 0., ..., 0., 0., 0.]), 'P9': array([0., 0., 0., ..., 0., 0., 0.]), 'D9': array([0., 0., 0., ..., 0., 0., 0.])}, {'time': array([ 0. , 0.1, 0.2, ..., 299.7, 299.8, 299.9]), 'I': array([10., 10., 10., ..., 0., 0., 0.]), 'S': array([60., 60., 60., ..., 0., 0., 0.]), 'M': array([40., 40., 40., ..., 0., 0., 0.]), 'R': array([0., 0., 0., ..., 0., 0., 0.]), 'P1': array([ 0., 0., 0., ..., 20., 20., 20.]), 'D1': array([ 0., 0., 0., ..., 80., 80., 80.]), 'P2': array([0., 0., 0., ..., 0., 0., 0.]), 'D2': array([0., 0., 0., ..., 0., 0., 0.]), 'P3': array([0., 0., 0., ..., 0., 0., 0.]), 'D3': array([0., 0., 0., ..., 0., 0., 0.]), 'P4': array([0., 0., 0., ..., 0., 0., 0.]), 'D4': array([0., 0., 0., ..., 0., 0., 0.]), 'P5': array([0., 0., 0., ..., 0., 0., 0.]), 'D5': array([0., 0., 0., ..., 0., 0., 0.]), 'P6': array([0., 0., 0., ..., 0., 0., 0.]), 'D6': array([0., 0., 0., ..., 0., 0., 0.]), 'P7': array([0., 0., 0., ..., 0., 0., 0.]), 'D7': array([0., 0., 0., ..., 0., 0., 0.]), 'P8': array([0., 0., 0., ..., 0., 0., 0.]), 'D8': array([0., 0., 0., ..., 0., 0., 0.]), 'P9': array([0., 0., 0., ..., 0., 0., 0.]), 'D9': array([0., 0., 0., ..., 0., 0., 0.])}, {'time': array([ 0. , 0.1, 0.2, ..., 299.7, 299.8, 299.9]), 'I': array([10., 10., 10., ..., 0., 0., 0.]), 'S': array([60., 60., 60., ..., 0., 0., 0.]), 'M': array([40., 40., 40., ..., 0., 0., 0.]), 'R': array([0., 0., 0., ..., 0., 0., 0.]), 'P1': array([ 0., 0., 0., ..., 20., 20., 20.]), 'D1': array([ 0., 0., 0., ..., 80., 80., 80.]), 'P2': array([0., 0., 0., ..., 0., 0., 0.]), 'D2': array([0., 0., 0., ..., 0., 0., 0.]), 'P3': array([0., 0., 0., ..., 0., 0., 0.]), 'D3': array([0., 0., 0., ..., 0., 0., 0.]), 'P4': array([0., 0., 0., ..., 0., 0., 0.]), 'D4': array([0., 0., 0., ..., 0., 0., 0.]), 'P5': array([0., 0., 0., ..., 0., 0., 0.]), 'D5': array([0., 0., 0., ..., 0., 0., 0.]), 'P6': array([0., 0., 0., ..., 0., 0., 0.]), 'D6': array([0., 0., 0., ..., 0., 0., 0.]), 'P7': array([0., 0., 0., ..., 0., 0., 0.]), 'D7': array([0., 0., 0., ..., 0., 0., 0.]), 'P8': array([0., 0., 0., ..., 0., 0., 0.]), 'D8': array([0., 0., 0., ..., 0., 0., 0.]), 'P9': array([0., 0., 0., ..., 0., 0., 0.]), 'D9': array([0., 0., 0., ..., 0., 0., 0.])}]
I intend to work on only M as follows:
for index in range(0, 3):
x_stochastic = s_result[index]['M']
x_stochastic=((s_result['M'][0]-s_result['M'][:])/s_result['M'][0])
plt.plot(s_trajectory['time'],x_stochastic , 'r')
plt.xlabel('Time')
plt.ylabel('Monomer Conversion,X')
The expected outcome is 3 different trajectories as shown in the above data. But this is what got graphically:
Solution 1:[1]
I couldn't get your code as provided to run. Furthermore in the data snipped you posted all three M Value series are indistinguishable.
I've taken the liberty to modify the data to
s_result = [{'time': np.array([0,100,200,300]),
'M': np.array([40,40,30,0])},
{'time': np.array([0,100,200,300]),
'M': np.array([40,10,5,0])},
]
The corrected loop
for index in range(0, len(s_result)):
x_stochastic = s_result[index]
x_stochastic=((x_stochastic['M'][0]-x_stochastic['M'][:])/x_stochastic['M'][0])
plt.plot(s_result[index]['time'],x_stochastic , 'r')
plt.xlabel('Time')
plt.ylabel('Monomer Conversion,X')
then produces two distinct traces as desired.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arnau |


