Skip to content

Figure handling - a suggestion for improvement #2

Description

@steview2000

First of all, thanks for the library. That is pretty much what I was looking for - a simple interface to gnuplot.

However, I was a bit unsatisfied with the figure handling. After I had plotted multiple figures and I wanted to zoom into one of them, after zooming out it replotted the last figure instead of the active figure. For example, after plotting data in 3 different figures, I want to zoom into figure(2). When I want to zoom out again, I hit "a", but instead of zooming out, it replotted figure(3). I checked and this is indeed a problem with Gnuplot, and not with your script. Also, all changes with PyGnuplot.c() are valid for all figures later on, which is sometimes annoying.

Therefore, I have updated your script so that for each figure a new Gnuplot-subprocess is started. Now, PyGnuplot.figure() switches between completely independent Gnuplot sessions.

The parts that I have changed:

class _emptyClass(object):
def __init__(self):
self.figNum = [1]
self.figNum[0] = 1
self.proc = [1]
self.proc[0] = _Popen(['gnuplot', '-p'], shell=False, stdin=_PIPE) # persitant -p
`_vc = _emptyClass()` `proc = _vc.proc[0]`
def figure(number=None, term='x11'):
'''Make Gnuplot plot in a new Window or update a defined one
figure(num=None, term='x11'):
>>> figure(2) # would create or update figure 2
>>> figure() # simply creates a new figure
returns the new figure number
'''
global proc

if not isinstance(number, int):
number = _vc.figNum[-1]+1

if number not in _vc.figNum:
_vc.proc.append(_Popen(['gnuplot', '-p'], shell=False, stdin=_PIPE)) # persitant -p
_vc.figNum.append(number)

_vc.figNum.sort()
proc = _vc.proc[_vc.figNum.index(number)]
c('set term '+str(term)+' '+str(number))
return number

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions