4

Using Sublime Text 2 or Atom (maybe other editors too), when running a simple plotting script in Python, the Python Launcher icon (the rocket) pops up every time I run the code. The icons add up in the Dock , and I have to close them individually. Is there any configuration to avoid this behavior?

With Sublime Text, for instance, Command + B is the default shortcut I use to run a script. I have not found this issue addressed in Atom's or Sublime Text's documentation (neither in Stack Exchange).

The script that I use is a basic fit to some data:

import csv
import matplotlib.pyplot as plt
from scipy.interpolate import *

with open('data.csv', 'rU') as mycsv:
    data = csv.reader(mycsv)
    x = []
    y = []
    for row in data:
        x.append(float(row[0]))
        y.append(float(row[1]))

p = polyfit(x, y, 2)
xp = linspace(-5, 1, 1000)

plt.scatter(x, y)
plt.plot(xp,polyval(p,xp),'r-', label='p1')
plt.show()
0

2 Answers 2

1

I'm not familiar with pyplot, but from the documentation, it looks like the show() method 'holds onto' ("blocks") the script until it is closed by some user interaction.

In non-interactive mode, display all figures and block until the figures have been closed;
A single experimental keyword argument, block, may be set to True or False to override the blocking behavior described above.

Other methods like ginput() and waitforbuttonpress() describe the blocking process.

You could test this by commenting out the last line and see if the icons persist.

0
1

In your setup Sublime Text is running the python script by running python script.py as if from the command line. This starts a new python interpreter process for each run. This is documented (and is the actual example used) in the Build Systems part Sublime Text Manual

Normally this is OK but in your case you are running a script that will stay open until it is manually closes. All these processes are independant and have no idea of the others and so you just keep getting more.

To have only one python process and thus one icon on the desktop you need a different set up. In general this is using a REPL (read-eval-print-loop) which passes all your python commands to one process. I am not a sublime text user so I don't know if a REPL from it can show graphics.

In your case of lots of graphs I would look at Juypter Notebooks. In Juypter python is started as an external process the kernal and your editor sends python command to it, thus there is one Python process that knows about all the graphs. A quick google suggests that there is a package Hermes for Sublime Text.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .