Rotate the axis of the figure generated by post2d.plot

Asked by Weimin Song

Dear colleagues,

I generated one figure using post2d.plot. However, the strange thing is the axises in the figure is opposite to what I want. So, how could I rotate the axis of the figure?

Link: https://www.dropbox.com/sh/vcxlo4kqksq282g/AADYwVDRKPq-A7funRBFPkDEa?dl=0

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Best Jan Stránský (honzik) said :
#1

Hi Weimin,
after a quick look, I did not find any solution (although I am not very
familiar with matplotlib). A dirty workaround is to create a new simulation
with bodies with swapped coordinates and swapped data and plot them:

######################################################
from yade import post2d
import pylab
import random
r = random.random

sphs = ([sphere((-.5+r(),-.5+r(),-1+2*r()),.05) for i in xrange(20)]) #
some random particles
O.bodies.append(sphs)

flattener = post2d.AxisFlatten(axis=1)
extractSomething = lambda b: 2*b.state.pos # extract something
extractSomething2 = lambda b: b.data # b.data is just temporary variable to
save the swapped data

# normal process
pylab.figure()
post2d.plot(post2d.data(extractSomething,flattener))

# get and swap positions of particles
poss = [b.state.pos for b in O.bodies]
poss = [Vector3(p[2],p[1],p[0]) for p in poss]
# get and swap data
data = [extractSomething(b) for b in O.bodies]
data = [Vector3(d[2],d[1],d[0]) for d in data]

O.switchScene() # not to indluence current simulation
# add particles with swapped coordinates
O.bodies.append([sphere(p,.05) for p in poss])
# assign them swapped data
for b in O.bodies:
  b.data = data[b.id]

pylab.figure()
post2d.plot(post2d.data(extractSomething2,flattener))

O.switchScene() # back to the original simulation

pylab.show()
######################################################

cheers
Jan

Revision history for this message
Weimin Song (wsong8) said :
#2

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