plot 2 figures

Asked by hafsa on 2019-02-12

hi everyone ,
i want to plot 2 figures the first is for kinetic energy and the second for pos_z of one particle .
i obtain just the second figure , why the first douen't plot ?
 there's my code :

def plotAddData():
   #ekin=kineticEnergy()/n
   plot.addData(i=O.iter,e=log(kineticEnergy()/n), **O.energy)
   # oscillation
   if O.iter >=1e4:
       O.engines=O.engines+[HarmonicMotionEngine(A=[0,0,1.], f=[0,0,2.6], fi = [0.0,0.0,0.0],ids =Cylinder)]
       # save in file
       plot.addData(i=O.iter,pos_z=O.bodies[0].state.pos[2])

plot.plots={'i':['e']+O.energy.keys()}
plot.plots={'i':['pos_z']}
plot.plot()
plot.live=True

than'k in advance

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2019-02-12
Last query:
2019-02-12
Last reply:
2019-02-12
Jan Stránský (honzik) said : #1

> plot.plots={'i':['e']+O.energy.keys()}
> plot.plots={'i':['pos_z']}

the second assignment just assign {'i':['pos_z']}, overwriting the previous values.

plot.plots = {'i': ..., 'i ': ...} # note the space in 'i ' [1]
or
plot.plots = {'i':('e',None,'pos_z')} # [1]

cheers
Jan

[1] https://yade-dev.gitlab.io/trunk/user.html#multiple-figures

hafsa (sebbah.hafsa) said : #2

hi Jan ,
i tried the both and after condition (O.iter>= 1e4) the the curve ( kinetic and pos_z) becomes transparent .

def plotAddData():
   #ekin=kineticEnergy()/n
   plot.addData(i=O.iter,e=log(kineticEnergy()/n), **O.energy)
   # oscillation
   if O.iter >=0.8*1e4:
       O.engines=O.engines+[HarmonicMotionEngine(A=[0,0,1.], f=[0,0,2.6], fi = [0.0,0.0,0.0],ids =Cylinder)]
       # save in file
       pos_z=O.bodies[0].state.pos[2]
       plot.addData(i=O.iter,pos_z=O.bodies[0].state.pos[2])

#plot.plots={'i':['e']+O.energy.keys()}
#plot.plots = {'i ':('e',None,'pos_z')}
plot.plots={'i':['pos_z',],'i ':['e']+O.energy.keys()}
plot.plot()
plot.live=True

Jan Stránský (honzik) said : #3

a MWE [1] please
Jan

[1] https://yade-dem.org/wiki/Howtoask

hafsa (sebbah.hafsa) said : #4

i tried plot.plots={'i':['pos_z',],'i ':['e']+O.energy.keys()} and when O.iter = 1e4 the curves of kinetic energy and pos_z become transparent .

Best Jan Stránský (honzik) said : #5

For next time, MWE = Minimal Working Example [1].

in your case, the plot becomes transparent because there are not continuous data to plot (plot .addData adds NaN in case some data are missing):

> plot.addData(i=O.iter,e=log(kineticEnergy()/n), **O.energy) # 1st plot.addData, adding NaN for pos_z
> if O.iter >=0.8*1e4:
> plot.addData(i=O.iter,pos_z=O.bodies[0].state.pos[2]) # 2nd plot.addData, adding NaN for e

solution:

if O.iter > ...:
   plot.addData(i=...,e=...,pos_z=...
else:
   plot.addData(i=...,e=...)

Jan

[1] https://yade-dem.org/wiki/Howtoask

hafsa (sebbah.hafsa) said : #6

Thanks Jan Stránský, that solved my question.