'ValueError: shape mismatch' when plotting

Asked by Rohit John on 2019-11-15


I am using Yade 2018.02b on a Virtual Box machine running Ubuntu 18.04.3 LTS. The host machine runs Windows 10.

I was trying to learn how to plot using the first tutorial given in the YADE tutorial page. (The one with a ball bouncing on another ball). I followed the commands given about plotting in the section Data mining. It works for a sometime then gives an error.

There was a post with a similar error. It recommended increasing iterPeriod in PyRunner by a few orders of magnitude. All it did was delay when the error occured
The code is given below

# basic simulation showing sphere falling ball gravity,
# bouncing against another sphere representing the support


# add 2 particles to the simulation
# they the default material (utils.defaultMat)
 # fixed: particle's position in space will not change (support)
 # this particles is free, subject to dynamics


# simulation loop -- see presentation for the explanation
  [Ig2_Sphere_Sphere_ScGeom()], # collision geometry
  [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
  [Law2_ScGeom_FrictPhys_CundallStrack()] # contact law -- apply forces
 # Apply gravity force to particles. damping: numerical dissipation of energy.

# set timestep to a fraction of the critical timestep
# the fraction is very small, so that the simulation is not too fast
# and the motion can be observed

# save the simulation, so that it can be reloaded later, for experimentation

from yade import plot
plot.plots={'t':('coordNum','unForce',None,'Ek')} # kinetic energy will have legend on the right as indicated by None separator.

def addPlotData():
        # this function adds current values to the history of data, under the names specified




The error that I get is given below

Unhandled exception in thread started by <function liveUpdate at 0x7f45b3db18c0>
ValueError Traceback (most recent call last)
/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py in liveUpdate(timestamp)
    506 for ax in axes:
    507 try:
--> 508 ax.relim() # recompute axes limits
    509 ax.autoscale_view()
    510 except RuntimeError: pass # happens if data are being updated and have not the same dimension at the very moment

/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in relim(self, visible_only)
   1936 for line in self.lines:
   1937 if not visible_only or line.get_visible():
-> 1938 self._update_line_limits(line)
   1940 for p in self.patches:

/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in _update_line_limits(self, line)
   1799 Figures out the data limit of the given line, updating self.dataLim.
   1800 """
-> 1801 path = line.get_path()
   1802 if path.vertices.size == 0:
   1803 return

/usr/lib/python2.7/dist-packages/matplotlib/lines.pyc in get_path(self)
    955 """
    956 if self._invalidy or self._invalidx:
--> 957 self.recache()
    958 return self._path

/usr/lib/python2.7/dist-packages/matplotlib/lines.pyc in recache(self, always)
    665 y = self._y
--> 667 self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
    668 self._x, self._y = self._xy.T # views

/home/intern/.local/lib/python2.7/site-packages/numpy/lib/stride_tricks.pyc in broadcast_arrays(*args, **kwargs)
    257 args = [np.array(_m, copy=False, subok=subok) for _m in args]
--> 259 shape = _broadcast_shape(*args)
    261 if all(array.shape == shape for array in args):

/home/intern/.local/lib/python2.7/site-packages/numpy/lib/stride_tricks.pyc in _broadcast_shape(*args)
    191 # use the old-iterator because np.nditer does not handle size 0 arrays
    192 # consistently
--> 193 b = np.broadcast(*args[:32])
    194 # unfortunately, it cannot handle 32 or more arguments directly
    195 for pos in range(32, len(args), 31):

ValueError: shape mismatch: objects cannot be broadcast to a single shape

Question information

English Edit question
Yade Edit question
No assignee Edit question
Last query:
Last reply:
Robert Caulk (rcaulk) said : #1

I am sorry to tell you: we are already aware of this and we *believe* this is a matplotlib bug [1]. If it is a matplotlib bug, there is nothing we can do about it at the moment :-(.


Rohit John (rohitkjohn) said : #2

Thanks for the quick reply.

Are there any other ways to plot or visualise what is going on when the simulation is running? I am testing some simulations so I need to see what is going on and check if things are proceeding the way I want it to.

Robert Caulk (rcaulk) said : #3

Technically, with a PyRunner[1] you can execute any code you want at each iteration. You could try just saving a custom plot to file each run, then you could look through those images as the simulation progresses.


Can you help with this problem?

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

To post a message you must log in.