HITS-MBM/conan

Non interactive backend for matplotlib

Opened this issue · 3 comments

Hello.
From what I've seen the matplotlib backend when running CONAN is left as the default for the system. Lately I've run into some issues that I wasn't running into before. They are detailed here: https://gist.github.com/ijpulidos/dc4b96f0be7c114b00d4eb5723c4b0be

As far as I can see, changing some lines in how matplotlib is imported fixes this issue, basically I did the following in the header of the conan.py file:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

As suggested in https://matplotlib.org/faq/howto_faq.html#working-with-threads and referenced in https://stackoverflow.com/questions/4706451/how-to-save-a-figure-remotely-with-pylab/4706614#4706614 . I think it would also improve the ability to run conan in parallel using threads or similar. I'm just not sure if this would end up having issues with other things or features from Conan, since I really haven't tested it extensively.

Ok, apparently the issue in the gist in my previous comment is related to matplotlib version. I run into it with an old matplotlib 2.2.2 but not with 3.2.2. So that's one thing. I still think there could be some benefits on using the "Agg" backend, though, specially in terms of thread safety.

I want to also report the issue I found with trying to use the interactive plots in Jupyter Notebooks immediately after installing the most recent Anaconda (2020.07) on a Windows 10 platform. The issue specifically was that only the upper left hand quartile of a plot would display and can be reproduced in a notebook by doing:

import matplotlib.pyplot as plt

%matplotlib notebook
# running the above in its own code cell

plt.figure()
plt.plot([1,5],[2,10])    #or any other plot

I was able to reproduce this in a minimum environment of only installing the latest versions of python (3.8.5), jupyter (1.0.0) and matplotlib (3,3,0).

After rolling back to matplotlib version 3.1.3 in the minimum environment and then in the complete Anaconda 2020.07 installation the issue was resolved for me.