Plot.plot() not working

Asked by Namzu

I am using Ubuntu 20.04 and Plot.plot() not working. I tried different examples in yade document. None of them are working. Can anyone help me to fix this? I am new to yade.

Question information

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

Hello,

> I am new to yade.

welcome :-)

please read [1] and provide more information.

> I am using Ubuntu 20.04

what Yade are you using?
System package? self-compiled?
Which version?
... ?

> Plot.plot() not working

Plot (capital P) should not work.
If referring to code, always write/paste code exactly used. Here assuming it should have been plot.plot()?

> I tried different examples in yade document

please give at least one specific example.

> None of them are working

what does "none are working" mean?
Do you get any error?
What are the symptoms? (errors? plot is shown, but not correctly? plot is shown but is not updating? ... ?)
... ?

Cheers
Jan

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

Revision history for this message
Namzu (namzzu) said :
#2

>what Yade are you using?
System package? self-compiled?

I installed it using sudo apt-get install yade.

>Which version?
Yade 2020.01a

python version 3.8.10
matplotlib version 3.6.0

> If referring to code, always write/paste code exactly used. Here assuming it should have been plot.plot()?

Sorry for the confusion. I meant plot.plot() only.

>please give at least one specific example.

I tried to run this code But I am getting "Attribute error: PathCollection.set() got an unexpected keyword argument 'verts' "which is related to matplotlib. plots are not shown. What i Guess is matplotlib version in my system and yade version is not matching. If yes, can you suggest which version I should use.

# gravity deposition in box, showing how to plot and save history of data,
# and how to control the simulation while it is running by calling
# python functions from within the simulation loop

# import yade modules that we will use below
from yade import pack, plot

# create rectangular box from facets
O.bodies.append(geom.facetBox((.5, .5, .5), (.5, .5, .5), wallMask=31))

# create empty sphere packing
# sphere packing is not equivalent to particles in simulation, it contains only the pure geometry
sp = pack.SpherePack()
# generate randomly spheres with uniform radius distribution
sp.makeCloud((0, 0, 0), (1, 1, 1), rMean=.05, rRelFuzz=.5)
# add the sphere pack to the simulation
sp.toSimulation()

O.engines = [
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb(), Bo1_Facet_Aabb()]),
        InteractionLoop(
                # handle sphere+sphere and facet+sphere collisions
                [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom()],
                [Ip2_FrictMat_FrictMat_FrictPhys()],
                [Law2_ScGeom_FrictPhys_CundallStrack()]
        ),
        NewtonIntegrator(gravity=(0, 0, -9.81), damping=0.4),
        # call the checkUnbalanced function (defined below) every 2 seconds
        PyRunner(command='checkUnbalanced()', realPeriod=2),
        # call the addPlotData function every 200 steps
        PyRunner(command='addPlotData()', iterPeriod=100)
]
O.dt = .5 * PWaveTimeStep()

# enable energy tracking; any simulation parts supporting it
# can create and update arbitrary energy types, which can be
# accessed as O.energy['energyName'] subsequently
O.trackEnergy = True

# if the unbalanced forces goes below .05, the packing
# is considered stabilized, therefore we stop collected
# data history and stop
def checkUnbalanced():
 if unbalancedForce() < .05:
  O.pause()
  plot.saveDataTxt('bbb.txt.bz2')
  # plot.saveGnuplot('bbb') is also possible

# collect history of data which will be plotted
def addPlotData():
 # each item is given a names, by which it can be the unsed in plot.plots
 # the **O.energy converts dictionary-like O.energy to plot.addData arguments
 plot.addData(i=O.iter, unbalanced=unbalancedForce(), **O.energy)

# define how to plot data: 'i' (step number) on the x-axis, unbalanced force
# on the left y-axis, all energies on the right y-axis
# (O.energy.keys is function which will be called to get all defined energies)
# None separates left and right y-axis
plot.plots = {'i': ('unbalanced', None, O.energy.keys)}

# show the plot on the screen, and update while the simulation runs
plot.plot()

O.saveTmp()

Revision history for this message
Jan Stránský (honzik) said :
#3

> But I am getting "Attribute error

please provide full error message ([1], point 2)

Cheers
Jan

Revision history for this message
Namzu (namzzu) said :
#4

This is the error I am getting.

AttributeError Traceback (most recent call last)
/usr/bin/yade in <module>
--> plot.plot()
/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py in plot(noShow, subPlots)
    598 .. note:: For backwards compatibility reasons, *noShow* option will return list of figures for multiple figures but a single figure (rather than list with 1 element) if there is only 1 figure.
    599 """
--> 600 createPlots(subPlots=subPlots)
    601 global currLineRefs
    602 figs=set([l.line.axes.get_figure() for l in currLineRefs])

/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py in createPlots(subPlots, scatterSize, wider)
    460 if yNameFuncs:
    461 axes.yadeYNames,axes.yadeYFuncs,axes.yadeXName,axes.yadeLabelLoc=yNames,yNameFuncs,pStrip,labelLoc # prepend yade to avoid clashes
--> 462 createLines(pStrip,plots_p_y1,isY1=True,y2Exists=len(plots_p_y2)>0)
    463 if axesWd>0:
    464 pylab.axhline(linewidth=axesWd,color='k')

/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py in createLines(pStrip, ySpecs, isY1, y2Exists)
    442 scatterPt=[0,0] if len(data[pStrip])==0 else (data[pStrip][current],data[d[0]][current])
    443 # if current value is NaN, use zero instead
--> 444 scatter=pylab.scatter(scatterPt[0] if not math.isnan(scatterPt[0]) else 0,scatterPt[1] if not math.isnan(scatterPt[1]) else 0,s=scatterSize,color=line.get_color(),**scatterMarkerKw)
    445 currLineRefs.append(LineRef(line,scatter,line2,data[pStrip],data[d[0]]))
    446 axes=line.axes

~/.local/lib/python3.8/site-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, data, **kwargs)
   2776 vmin=None, vmax=None, alpha=None, linewidths=None, *,
   2777 edgecolors=None, plotnonfinite=False, data=None, **kwargs):
-> 2778 __ret = gca().scatter(
   2779 x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
   2780 vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,

~/.local/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1421 def inner(ax, *args, data=None, **kwargs):
   1422 if data is None:
-> 1423 return func(ax, *map(sanitize_sequence, args), **kwargs)
   1424
   1425 bound = new_sig.bind(ax, *args, **kwargs)

~/.local/lib/python3.8/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs)
   4624 "No data for colormapping provided via 'c'. "
   4625 f"Parameters {keys_str} will be ignored")
-> 4626 collection._internal_update(kwargs)
   4627
   4628 # Classic mode only:

~/.local/lib/python3.8/site-packages/matplotlib/artist.py in _internal_update(self, kwargs)
   1184 The lack of prenormalization is to maintain backcompatibility.
   1185 """
-> 1186 return self._update_props(
   1187 kwargs, "{cls.__name__}.set() got an unexpected keyword argument "
   1188 "{prop_name!r}")

~/.local/lib/python3.8/site-packages/matplotlib/artist.py in _update_props(self, props, errfmt)
   1158 func = getattr(self, f"set_{k}", None)
   1159 if not callable(func):
-> 1160 raise AttributeError(
   1161 errfmt.format(cls=type(self), prop_name=k))
   1162 ret.append(func(v))

AttributeError: PathCollection.set() got an unexpected keyword argument 'verts'

Revision history for this message
Jan Stránský (honzik) said :
#5

> matplotlib version 3.6.0
> ~/.local/lib/python3.8/site-packages/matplotlib/pyplot.py

it seems like you have installed matplotlib with pip, right?

Documentation [2] suggest using "system version" (python3-matplotlib package), which should be version 3.1.2 [3].

You can try several options:
- uninstall pip version and install system version of matplotlib
- install matplotlib with pip, but version 3.1.2.
- use yadedaily [4] which should (could?) work with newer version

Cheers
Jan

[2] https://yade-dem.org/doc/installation.html#prerequisites
[3] https://packages.ubuntu.com/focal/python3-matplotlib
[4] https://yade-dem.org/doc/installation.html#packages

Can you help with this problem?

Provide an answer of your own, or ask Namzu for more information if necessary.

To post a message you must log in.