Problem with matplotlib.pyplot

Asked by Son Pham Thai

Hi all,

I am using Ubuntu 16.04 and Yade-daily package.

I got this problem when I run a simple "plot":

a=[1,2,3]
b=[2,3,4]
import matplotlib.pyplot as plt
plt.plot(a,b)

---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/home/son/Desktop/myYade/install/bin/yade in <module>()
      2 b=[2,3,4]
      3 import matplotlib.pyplot as plt
----> 4 plt.plot(a,b)

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in plot(*args, **kwargs)
   2978 @_autogen_docstring(Axes.plot)
   2979 def plot(*args, **kwargs):
-> 2980 ax = gca()
   2981 # allow callers to override the hold state by passing hold=True|False
   2982 washold = ax.ishold()

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in gca(**kwargs)
    801 """
    802
--> 803 ax = gcf().gca(**kwargs)
    804 return ax
    805

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in gcf()
    448 return figManager.canvas.figure
    449 else:
--> 450 return figure()
    451
    452 fignum_exists = _pylab_helpers.Gcf.has_fignum

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
    421 frameon=frameon,
    422 FigureClass=FigureClass,
--> 423 **kwargs)
    424
    425 if figLabel:

/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
     77 FigureClass = kwargs.pop('FigureClass', Figure)
     78 figure = FigureClass(*args, **kwargs)
---> 79 return new_figure_manager_given_figure(num, figure)
     80
     81

/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
     85 """
     86 _focus = windowing.FocusManager()
---> 87 window = Tk.Tk()
     88 window.withdraw()
     89

/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
   1760 if baseName is None:
   1761 import os
-> 1762 baseName = os.path.basename(sys.argv[0])
   1763 baseName, ext = os.path.splitext(baseName)
   1764 if ext not in ('.py', '.pyc', '.pyo'):

IndexError: list index out of range

Any help is greatly appreciate!
Thank you :)
Son.

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

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

Hello,
on Ubuntu 16.04 I just installed yadedaily, tried your code, but got no error.. Do you run any code before these instructions, or you get the error in fresh yadedaily session?
cheers
Jan

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#2

Hi Jan,

I used Ubuntu 14.04 and there was no problem. When I install Ubuntu 16 and install Yade, I got this problem. I have tried again and I think the problem could somehow relate to this (part of instruction for installation in [1]):

sudo apt-get install cmake git freeglut3-dev libloki-dev \
libboost-all-dev fakeroot dpkg-dev build-essential g++ \
python-dev ipython python-matplotlib libsqlite3-dev python-numpy python-tk gnuplot \
libgts-dev python-pygraphviz libvtk6-dev python-numpy libeigen3-dev \
python-xlib python-pyqt5 pyqt5-dev-tools python-pyqt5.qtwebkit gtk2-engines-pixbuf python-argparse \
libqglviewer-dev python-imaging libjs-jquery python-sphinx python-git python-bibtex \
libxmu-dev libxi-dev libcgal-dev help2man libbz2-dev zlib1g-dev python-minieigen

I try re-running this command again with separated line (not using \ anymore) and the problem with plot function is gone.

[1]. https://yade-dem.org/doc/installation.html

My problem has been solved.

Thank you ;)
Son

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#3

Hi,

What a shame on me, I just realized that I was in my Ubuntu 14 OS (not Ubuntu 16), that's why I did not have the mentioned problem. The problem in Ubuntu 16 is still there.

@Jan,
I did not run any code before, just fresh start Yade and run that code and got the above error.

Revision history for this message
Jérôme Duriez (jduriez) said :
#4

Hi,

What happens if you launch these commands directly in Python ?

(Eg ask for "ipython" instead of "yadedaily" in your terminal, then type the commands you mentioned)

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#5

Hi Jérôme,

Using ipython, I got no error:

Out[4]: [<matplotlib.lines.Line2D at 0x7f5552281ad0>]

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

What is the version of your yadedaily? i.e. if you start it, it writes (in my case which works) "Welcome to Yade 2018.02b-75-657a5bd~xenial"
thanks
Jan

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#7

Hi Jan,

I followed this instruction:
https://yade-dem.org/doc/installation.html#compilation

I downloaded the zip file from :
https://github.com/yade/trunk

and then exact that zip file to my "trunk" folder.

By doing this, I got version id for my Yade as "Unknown"

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

Ok, now I am a bit confused:

> I am using Ubuntu 16.04 and Yade-daily package.

> I followed this instruction: https://yade-dem.org/doc/installation.html#compilation
> I downloaded the zip file from : https://github.com/yade/trunk
> and then exact that zip file to my "trunk" folder.
> By doing this, I got version id for my Yade as "Unknown"

These two your statements are completely different. Please describe more how you installed the problematic version of yade and how you run it..

Another test, if you install default Ubuntu yade
sudo apt-get install yade
start "yade" in terminal and use those commands, do you still have the error?

cheers
Jan

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#9

Hi Jan,

1. What I have done:

sudo add-apt-repository ppa:yade-users/external
sudo apt-get update

sudo apt-get install cmake git freeglut3-dev libloki-dev \
libboost-all-dev fakeroot dpkg-dev build-essential g++ \
python-dev ipython python-matplotlib libsqlite3-dev python-numpy python-tk gnuplot \
libgts-dev python-pygraphviz libvtk6-dev python-numpy libeigen3-dev \
python-xlib python-pyqt5 pyqt5-dev-tools python-pyqt5.qtwebkit gtk2-engines-pixbuf python-argparse \
libqglviewer-dev python-imaging libjs-jquery python-sphinx python-git python-bibtex \
libxmu-dev libxi-dev libcgal-dev help2man libbz2-dev zlib1g-dev python-minieigen

(after this command, i got:
Note, selecting 'libpython2.7-stdlib' instead of 'python-argparse'
E: Unable to locate package python-pyqt5
E: Unable to locate package python-pyqt5.qtwebkit
E: Couldn't find any package by regex 'python-pyqt5.qtwebkit'

sudo apt-get install python-gts
sudo apt-get install libopenblas-dev libsuitesparse-metis-dev

sudo add-apt-repository ppa:yade-users/external
sudo apt-get update

My folder structure:
myYade/
        trunk/ ## downloaded from https://github.com/yade/trunk
        build/ ##
        install/ ## initially is a blank folder

 cd Desktop/myYade/build

cmake -DCMAKE_INSTALL_PREFIX=/home/son/Desktop/myYade/install /home/son/Desktop/myYade/trunk -DUSE_QT5=OFF -DTWOPHASEFLOW=ON -DDEBUG=ON

make -j4

make install

cd

cd Desktop/myYade/install/bin

./yade-Unknown

2. When I installed default Ubuntu yade by:
sudo apt-get install yade

Then I got no error with those plot commands:

 -> [4]: [<matplotlib.lines.Line2D at 0x7fbbc40673d0>]

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

Thanks for clarification, now it is clear that what you use is not "Yade-daily package" :-)
Is it possible for you to try to recompile with -DUSE_QT5=ON ?
cheers
Jan

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#11

Hi Jan,

When I recompiled with -DUSE_QT5=ON, I got cmake error:

CMake Error at CMakeLists.txt:246 (FIND_PACKAGE):
  Could not find a package configuration file provided by "Qt5" with any of
  the following names:

    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
  to a directory containing one of the above files. If "Qt5" provides a
  separate development package or SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred!

Revision history for this message
Jérôme Duriez (jduriez) said :
#12

For further clarification Son, what we refer to with "yade-daily package" is a Yade version that Linux users can install without compiling anything, using classical Linux package management tools (like apt-get, ..)
That corresponds to https://yade-dem.org/doc/installation.html#packages (and only this "Packages" part of the installation webpage)

All installation instructions starting from https://yade-dem.org/doc/installation.html#source-code refer to an installation through source code compilation. You got this source code in the zip file you downloaded from gitHub.

Lastly, your "unknown" is not the "version" of your Yade, it's just a suffix appended to the Yade executable (Python script, actually) and that you could specify during compilation process (but you did not, thus "unknown")

What we actually call Yade version is what Yade (whatever the installation method) outputs at startup. Give a closer look to your terminal and you should see something like Jan mentioned in #6, eg 2018.02b-75-657a5bd~xenial.
This reflects the development stage that is behind your Yade program, and is supposed to change with time (if you update your yade* packages, or if you download in a couple of weeks another zip file from gitHub)

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

Concerning your errors, I don't know how to fix them, please open a new question with the problem compiling with -DUSE_QT5=ON.
Jan

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#14

Hi Jérôme,

Thank you for the YADE installation clarification and I am sorry for my wrong description regarding "yade-daily package".

Considering the YADE version I have now:
$ ./yade-Unknown
Welcome to Yade Unknown

DEBUG /home/son/Desktop/myYade/trunk/core/Omega.hpp:106 Omega: Constructing Omega.

DEBUG /home/son/Desktop/myYade/trunk/core/Omega.cpp:209 loadPlugins: Loading plugin /home/son/Desktop/myYade/install/lib/x86_64-linux-gnu/yade-Unknown/libyade.so

DEBUG /home/son/Desktop/myYade/trunk/core/Omega.cpp:134 buildDynlibDatabase: called with 299 plugins.

...

DEBUG /home/son/Desktop/myYade/trunk/pkg/dem/FlatGridCollider.cpp:44 initIndices: sphereIdx=1
DEBUG /home/son/Desktop/myYade/trunk/pkg/dem/FlatGridCollider.cpp:44 initIndices: sphereIdx=1

TCP python prompt on localhost:9000, auth cookie `eyuscd'
XMLRPC info provider on http://localhost:21000
[[ ^L clears screen, ^U kills line. F8 plot. ]]

And by the way, when I press F8, I got this error:

Yade [1]: import yade.plot; yade.plot.plot();
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/home/son/Desktop/myYade/install/bin/yade-Unknown in <module>()
----> 1 import yade.plot; yade.plot.plot();

/home/son/Desktop/myYade/install/lib/x86_64-linux-gnu/yade-Unknown/py/yade/plot.pyc in plot(noShow, subPlots)
    595 global currLineRefs
    596 figs=set([l.line.axes.get_figure() for l in currLineRefs])
--> 597 if not hasattr(list(figs)[0],'show') and not noShow:
    598 import warnings
    599 warnings.warn('plot.plot not showing figure (matplotlib using headless backend?)')

IndexError: list index out of range

My initial desire is how to fix the error of this "plot" function.

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

> My initial desire is how to fix the error of this "plot" function.

you need to define plot.plots before:

from yade import plot
plot.plots = {'x':'y'} # or something else, see [1]

Jan

[1] https://yade-dem.org/doc/user.html#plotting-variables

Revision history for this message
Son Pham Thai (pham-thai-son-987) said :
#16

Hi,

Sorry for the late reply, I just had a meeting.

I have also tried installing Yade in another PC (with Ubuntu 14.04) and I got the same error.

I just want to know what my mistake is.

Thank you all for your time and advise!
Cheers,
Son

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#17

Hi Son,
As advised some time ago downloading the zip tarball is the last thing you want to do.
I again suggest to checkout using git. Also yadedaily should have the TWOPHASEFLOW feature enabled in latest versions, so you don't really need to compile, hopefully.
Cheers
Bruno

Can you help with this problem?

Provide an answer of your own, or ask Son Pham Thai for more information if necessary.

To post a message you must log in.