[Matplotlib-users] Mac OS: Can't get rid of 286 figures.

I am new to macplotlib and can only do the simplest things but there are many hidden complexities I can’t figure out that are now killing me. My big problem is everytime I plot I get a new ‘figure’ which I first thought was just a mysterious incrementing number but in fact seems to be some kind of persistent object which consumes resources and won’t go away. I don’t even know what a figure is. Where does it exist? Where is it’s state recorded? How do I get rid of them? Now I have so ‘figures’ many that performance is degraded and matplotlib is becoming unusable. I have many times closed them all by patiently clicking the close box of all 286 (now empty) windows but that apparently only hides them because they all pop up again when I make a new plot. I tried killing python but they all reappear the next time I run a python script. The top of my plot script now has the following code but it apparently doesn’t do anything:

plt.close(‘all’)
for i in range(285):
plt.close(i)

I rebooted but the mess all comes back.

From many google searches I’ve recently discovered this is all apparently part of something normally hidden called a backend which is another thing I never heard of before this problem got out of control. I started using matplotlib from various online pyplot tutorials. The words ‘close’, ‘backend’ and ‘figure’ were never mentioned in any of them, so I had no warning.

My questions:

  1. Is this the right forum for this problem?

  2. is there an easy way to get rid of figures. Can I reset or uninstall/reinstall something that will allow me to start over so I can use matplotlib again?

  3. Where is this hidden infrastrastructure documented? What is its name? What keywords do I need to google to figure this out.

  4. How do I do simple plots which go away when I am done looking at them? I have no current need for persistent plots.

  5. Why is this so hard? I just want to plot some data.

Thanks,

-steve

Versions:

Python 3.7.6 installed by homebrew

Matplotlib 3.0.3

OS: Catalina 10.15.3

MacBook Pro

I am using matplotlib 3.2 with python 3.8.2 from the python.org installer in macOS 10.15 and I don't see this problem of persistent plots. Can you post the code you're using to generate your plots? In my scripts, plt.close('all') closes all plot windows. When you say that "the mess all comes back", do you mean the 286 plots show up after running your script or do they show up when you just import matplotlib from the python repl?

The Matplotlib usage faq has information on figures, axes, etc - https://matplotlib.org/faq/usage_faq.html

RealPython has a nice introductory matplotlib tutorial that mentions the problem with having too many plots open - Python Plotting With Matplotlib (Guide) – Real Python

Since you say you just want to plot some data, you might want to try matplotlib wrappers or alternatives. Jake VanderPlas gave a nice talk at PyCon 2017 about the Python Visualization Landscape that mentions a few, such as bokeh, seaborn, plotly and altair. The talk is a few years old but still has useful information.

I haven't used these next two, so I can't tell you if they are easier to use than using matplotlib directly -
Veusz is a python package with "GUI, command-line, and scripting interfaces". There is a macOS installer

https://veusz.github.io

EasyPlot is "A matplotlib wrapper written in Python to enable fast and easy creation of reusable plots."

Hth,
Scott

···

On Mar 7, 2020, at 3:48 PM, Steve Morris <steve@judgement.com> wrote:

I am new to macplotlib and can only do the simplest things but there are many hidden complexities I can't figure out that are now killing me. My big problem is everytime I plot I get a new 'figure' which I first thought was just a mysterious incrementing number but in fact seems to be some kind of persistent object which consumes resources and won't go away. I don't even know what a figure is. Where does it exist? Where is it's state recorded? How do I get rid of them? Now I have so 'figures' many that performance is degraded and matplotlib is becoming unusable. I have many times closed them all by patiently clicking the close box of all 286 (now empty) windows but that apparently only hides them because they all pop up again when I make a new plot. I tried killing python but they all reappear the next time I run a python script. The top of my plot script now has the following code but it apparently doesn't do anything:
    plt.close('all')
    for i in range(285):
        plt.close(i)

I rebooted but the mess all comes back.

From many google searches I've recently discovered this is all apparently part of something normally hidden called a backend which is another thing I never heard of before this problem got out of control. I started using matplotlib from various online pyplot tutorials. The words 'close', 'backend' and 'figure' were never mentioned in any of them, so I had no warning.

My questions:

1) Is this the right forum for this problem?
2) is there an easy way to get rid of figures. Can I reset or uninstall/reinstall something that will allow me to start over so I can use matplotlib again?
3) Where is this hidden infrastrastructure documented? What is its name? What keywords do I need to google to figure this out.
4) How do I do simple plots which go away when I am done looking at them? I have no current need for persistent plots.
5) Why is this so hard? I just want to plot some data.

Thanks,

-steve

Versions:
Python 3.7.6 installed by homebrew
Matplotlib 3.0.3
OS: Catalina 10.15.3
MacBook Pro

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@python.org
Matplotlib-users Info Page

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

Hi Steve,

In addition to Scott’s excellent list of resources, I’d like to recommend “effective matplotlib” from Practical Business Python:

https://pbpython.com/effective-matplotlib.html

It answers a lot of your questions about the hierarchy of objects of matplotlib.

Please bear in mind that matplotlib is an old library (started in 2001 I believe) so it’s hard to ensure that all information out there is totally up to date. This is the right forum to get up to date information. On Stack Overflow, be sure to look for more recent answers than the “accepted” one, in case there is a newer way of doing things.

Juan.

···

On 8 Mar 2020, at 7:49 am, Steve Morris steve@judgement.com wrote:

I am new to macplotlib and can only do the simplest things but there are many hidden complexities I can’t figure out that are now killing me. My big problem is everytime I plot I get a new ‘figure’ which I first thought was just a mysterious incrementing number but in fact seems to be some kind of persistent object which consumes resources and won’t go away. I don’t even know what a figure is. Where does it exist? Where is it’s state recorded? How do I get rid of them? Now I have so ‘figures’ many that performance is degraded and matplotlib is becoming unusable. I have many times closed them all by patiently clicking the close box of all 286 (now empty) windows but that apparently only hides them because they all pop up again when I make a new plot. I tried killing python but they all reappear the next time I run a python script. The top of my plot script now has the following code but it apparently doesn’t do anything:

plt.close(‘all’)
for i in range(285):
plt.close(i)

I rebooted but the mess all comes back.

From many google searches I’ve recently discovered this is all apparently part of something normally hidden called a backend which is another thing I never heard of before this problem got out of control. I started using matplotlib from various online pyplot tutorials. The words ‘close’, ‘backend’ and ‘figure’ were never mentioned in any of them, so I had no warning.

My questions:

  1. Is this the right forum for this problem?
  1. is there an easy way to get rid of figures. Can I reset or uninstall/reinstall something that will allow me to start over so I can use matplotlib again?
  1. Where is this hidden infrastrastructure documented? What is its name? What keywords do I need to google to figure this out.
  1. How do I do simple plots which go away when I am done looking at them? I have no current need for persistent plots.
  1. Why is this so hard? I just want to plot some data.

Thanks,

-steve

Versions:

Python 3.7.6 installed by homebrew

Matplotlib 3.0.3

OS: Catalina 10.15.3

MacBook Pro


Matplotlib-users mailing list
Matplotlib-users@python.org
Matplotlib-users Info Page