Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Superfluous matplotlib figures shown #158

Closed
willfurnass opened this issue Jul 25, 2018 · 22 comments
Closed

Superfluous matplotlib figures shown #158

willfurnass opened this issue Jul 25, 2018 · 22 comments
Assignees
Labels
Milestone

Comments

@willfurnass
Copy link
Collaborator

Various statements in the MuMoTtest.ipynb Notebook result in bare, superfluous Figure objects being displayed before the Figures that those statements should produce. An example statement is:

bookmark1 = model4.bifurcation('s', 'A-B', initialState = {'U': 0.0, 'A': 1.0, 'B': 0.0}, initBifParam = 2.0, params = [('\\mu', 2.0), ('\\Delta', 2.0), ('plotLimits', 1), ('systemSize', 1)], initWigdets = {'\\mu': [3, 1.1, 5, 0.1], '\\Delta': [0.1, 0, 5, 0.1]}, bookmark = False)

Could there be a superfluous call to matplotlib.pyplot.figure() somewhere?

More info:

pip freeze | grep -E 'matplotlib|ipython|notebook'                                                                                                                                   
ipython==6.4.0                                                                                                                                                                               
ipython-genutils==0.2.0                                                                                                                                                                      
matplotlib==2.2.2                                                                                                                                                                            
notebook==5.6.0

Noticed using commit af774f5

@willfurnass willfurnass added this to the First release milestone Jul 25, 2018
@jarmarshall
Copy link
Contributor

This is old behaviour - definitely using MumotEnv?

@willfurnass
Copy link
Collaborator Author

Nope, just the mandatory dependencies inc minimum versions listed in setup.py. Know what fixed this previously? Had a look for pertinent GH Issues but didn't find anything.

NB continuous integration runs currently install MuMoT plus dependencies in a virtualenv using the package info in setup.py; I could change this to use conda but want the dependency info in setup.py to be right, as that defines what's absolutely required to get expected functionality.

@jarmarshall
Copy link
Contributor

@joefresna @tbose1 do you recall?

@jarmarshall
Copy link
Contributor

This is probably to do with the version of matplotlib, ipywidgets, or another of the libraries. @tbose1 is on holiday this week but I can talk to him next week about it when we're at the same conference, I hope.

@willfurnass
Copy link
Collaborator Author

Yes, likely. I tried forcing matplotlib, ipywidgets and sympy versions in setup.py so they matched those in environment.yml but that didn't help.

@jarmarshall
Copy link
Contributor

Running a build from today via MyBinder does not exhibit this problem, as far as I can see...

@willfurnass
Copy link
Collaborator Author

MyBinder uses the conda environment.yml. The problem seems to be with a virtualenv created with the minimal set of essential dependencies defined in setup.py.

@tbose1
Copy link
Contributor

tbose1 commented Sep 4, 2018

The original double-figure problem was solved with commit 473e975 (committed on 3rd May 2018).

I remember trying a lot of things.
The solution that worked in MumotEnv was to modify the following function _buildFig() (essentially this means turning interactive mode on and off with plt.ion() and plt.ioff() ):

def _buildFig(object, figure = None):
    global figureCounter
    object._figureNum = figureCounter
    if figureCounter==1:
        plt.ion()
    else:
        plt.ioff()
    figureCounter += 1
    with warnings.catch_warnings(): # ignore warnings when plt.hold has been deprecated in installed libraries - still need to try plt.hold(True) in case older libraries in use
        warnings.filterwarnings("ignore",category=MatplotlibDeprecationWarning)
        warnings.filterwarnings("ignore",category=UserWarning)
        plt.hold(True)  
    if figure == None:
        if figureCounter>2:
            plt.ion()
        object._figure = plt.figure(object._figureNum) 
    else:
        object._figure = figure

This function replaced the previous version ( renamed to _buildFigOLD() ):

def _buildFigOLD(object, figure = None):
    global figureCounter
    object._figureNum = figureCounter
    figureCounter += 1

@willfurnass
Copy link
Collaborator Author

@tbose1 Can you add a docstring for _buildFig explaining what the function does.

@tbose1
Copy link
Contributor

tbose1 commented Sep 21, 2018

Added docstring to buildFig in commit eb90d05.

@jarmarshall
Copy link
Contributor

The environments created via pip and conda differ markedly in the library versions installed - not being expert in pip or conda I am not sure of how to ensure consistency - I have briefly tried downgrading matplotlib, ipython, and ipywidgets to the versions in environment.yml - this failed to solve the problem and created new problems. Is there an elegant way of copying a minimal working environment to requirements.txt @willfurnass ?

@willfurnass
Copy link
Collaborator Author

Here's a maximal working requirements.txt. Not yet had chance to pick apart which package(s)/versions are required to avoid the duplicate figure issue...

@jarmarshall
Copy link
Contributor

I'm a bit confused now - is requirements.txt deprecated, and all requirements should go in setup.py?

jarmarshall added a commit to jarmarshall/MuMoT that referenced this issue Oct 11, 2018
@jarmarshall
Copy link
Contributor

I've found the old issue this cropped up in (#108)
I've copied those requirements in full into setup.py in my branch https://github.com/jarmarshall/MuMoT
There are various build errors, and then a notebook error that looks familiar, but I can't find the relevant issue:

TraitError: The 'selected_index' trait of an Accordion instance must be an int, but a value of None <class 'NoneType'> was specified.

@willfurnass it seems we're just chasing our tails now trying to get virtualenv working - you said you could change the continuous integration to work with conda - I think we should do that and only support conda installation at this point.

@jarmarshall
Copy link
Contributor

I've noticed something else - in the virtualenv installation figures are no longer in interactive mode (pannable, etc.) - this may be related - have tried installing ipympl and using the matplotlib widget magic but this hasn't made a difference - want to check if the conda installation is still in interactive mode but the MyBinder site has just spent 10 minutes failing to build...

@jarmarshall
Copy link
Contributor

Having checked the conda installation and MyBinder deployment too, both work in interactive mode for plots correctly - by contrast the virtualenv approach does not, and I think this is the root of this issue. It seems that virtualenvs may not play nicely with matplotlib, e.g. see https://matplotlib.org/faq/virtualenv_faq.html (although not sure when that was written) - I recommend we only support the conda installation route and change the continuous integration over to use this @willfurnass

@willfurnass
Copy link
Collaborator Author

Addressed by #210

@tbose1
Copy link
Contributor

tbose1 commented Feb 11, 2019

Installation of MuMoT within the mumot-env conda environment following the documentation brings back the superfluous figure problem on my system (macOS), i.e. each time a slider is changed a new figure appears below the previous one. Also the rendering of the figures is affected. This is probably due to pinning matplotlib to a version <3.0 which currently installs matplotlib=2.2.3. Pinning the version to matplotlib=2.1.2 seems to solve this problem. The most recent version is 3.0.2 but this appears to be incompatible with other dependencies.

@tbose1 tbose1 reopened this Feb 11, 2019
@tbose1
Copy link
Contributor

tbose1 commented Feb 11, 2019

Update: pinning matplotlib to another version doesn't help. I'm working on another solution.

@tbose1
Copy link
Contributor

tbose1 commented Feb 12, 2019

Solved with commit 97e1074. Added the following to the MuMoT code (chooses TkAgg backend if mac-user):

if sys.platform == "darwin": #if operating system is macOS
import matplotlib
matplotlib.use('TkAgg')

@tbose1 tbose1 closed this as completed Feb 12, 2019
@willfurnass
Copy link
Collaborator Author

@tbose1 I suggest also adding comments above those three lines to explain why they're needed.

@tbose1
Copy link
Contributor

tbose1 commented Feb 13, 2019

Added comments via 6d9520c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants