← Back to team overview

yade-users team mailing list archive

[Question #688342]: how to use plt.plot in Yade?

 

New question #688342 on Yade:
https://answers.launchpad.net/yade/+question/688342

Hello,

I am using Ubuntu 18.04, and Yade 2019-08-08.git-775ae74

I coded a triaxial test which works properly now (thanks to all of you for your helps) and I can get the plots for macro variables such as e22, s22, etc. successfully. However, the plot.plot() function in YADE it is not as flexible as matplotlib(pyplot) in python and I could not find what I want as I wen through the YADE documentation (BTW: the yade-dem.org does not open for me now).

My main problem with plot.plot is I cannot make multiple figures for multiple plots (not subplots). 

So, that is why I tried to use plt.plot() to plot e22, s22,... in the way I want but I give error as these variables are defined in a function(addplot history function). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
My code for this part is as follows:

from matplotlib import pyplot as plt

fig1, ax1=plt.subplots(figsize=(15, 10))
fig2, ax2=plt.subplots(figsize=(15, 10))
fig3, ax4=plt.subplots(figsize=(15, 10))
fig3, ax4=plt.subplots(figsize=(15, 10))

ax1.plot(e22,ev,color='k',linestyle='--',marker='D',linewidth=1,label='harchi')
ax1.legend()
ax1.set_title('sample graph')
ax1.set_xlabel('age')
ax1.set_ylabel('salary')
ax1.grid()
fig1.tight_layout()
fig1.savefig('plot1.eps', format='eps')

ax2.plot(i,s22,color='k',linestyle='--',marker='D',linewidth=1,label='harchi')
ax2.legend()
ax2.set_title('sample graph')
ax2.set_xlabel('age')
ax2.set_ylabel('salary')
ax2.grid()
fig2.tight_layout()
fig2.savefig('plot2.eps', format='eps')

ax3.plot(e22,s22,color='k',linestyle='--',marker='D',linewidth=1,label='harchi')
ax3.legend()
ax3.set_title('sample graph')
ax3.set_xlabel('age')
ax3.set_ylabel('salary')
ax3.grid()
fig3.tight_layout()
fig3.savefig('plot3.eps', format='eps')

ax4.plot(i,s11,color='k',linestyle='--',marker='D',linewidth=1,label='harchi')
ax4.legend()
ax4.set_title('sample graph')
ax4.set_xlabel('age')
ax4.set_ylabel('salary')
ax4.grid()
fig4.tight_layout()
fig4.savefig('plot1.eps', format='eps')


plt.show()

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The error is as follows:

============ RECORD AND PLOT DATA ============
Traceback (most recent call last):
  File "/home/ehsan/yade/install/bin/yade-2019-08-08.git-775ae74", line 336, in runScript
    execfile(script,globals())
  File "/usr/lib/python3/dist-packages/past/builtins/misc.py", line 82, in execfile
    exec_(code, myglobals, mylocals)
  File "test.py", line 295, in <module>
    print(e)
NameError: name 'e22' is not defined

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

P.S: I developed my code based on [1]
[1] https://gitlab.com/yade-dev/trunk/blob/master/examples/triax-tutorial/script-session1.py

Thank you,
Ehsan

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.