Skip to content

Commit

Permalink
Simplification of axis API, plus some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
István Bozsó committed Jul 10, 2019
1 parent 8258c3e commit fa534b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
36 changes: 25 additions & 11 deletions gnuplot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
"arrow", "call", "colorbar", "debug", "histo", "label", "line", "linedef",
"margins", "multiplot", "obj", "output", "palette", "plot", "data",
"file", "grid", "refresh", "replot", "reset", "save", "set", "silent",
"splot", "style", "term", "title", "unset_multi", "colors",
"dollar", "zero", "one", "two", "three", "x", "y", "Symbol",
"xaxis", "yaxis", "zaxis"
"splot", "style", "term", "title", "unset_multi", "colors",
"x", "y", "z", "sym", "dollar", "col"
)


Expand All @@ -48,10 +47,10 @@
"startup":
"""
set style line 11 lc rgb 'black' lt 1
set border 3 back ls 11
set border 3 back ls 11 lw 2.5
set tics nomirror
set style line 12 lc rgb 'black' lt 0 lw 1
set grid back ls 12
set grid back ls 12 lw 2.5
"""
}

Expand Down Expand Up @@ -102,9 +101,9 @@ def call(*commands):

call(config["startup"])

xaxis = Axis(call, "x")
yaxis = Axis(call, "y")
zaxis = Axis(call, "z")
x = Axis(call, "x")
y = Axis(call, "y")
z = Axis(call, "z")


def refresh(plot_cmd):
Expand Down Expand Up @@ -518,13 +517,28 @@ def f(self, other):
Symbol = type("Symbol", (str,), {"__%s__" % op: make_operator(op)
for op in operators.keys()})


def dollar(num):
return Symbol("$%d" % num)


zero, one, two, three, x, y = \
dollar(0), dollar(1), dollar(2), dollar(3), Symbol("x"), Symbol("y")
class Dollar(object):
cache = {num: dollar(num) for num in range(11)}

def __getitem__(self, num):
cache = Dollar.cache
if num in cache:
return cache[num]
else:
tmp = dollar(num)
cache[num] = tmp
return tmp

col = Dollar()

sym = type("Symbols", (object,), {
"x": Symbol("x"),
"y": Symbol("y"),
})


class PlotDescription(object):
Expand Down
17 changes: 12 additions & 5 deletions gnuplot/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@

class Axis(object):
def __init__(self, call, name="x"):
self.call, self.name, self._range = call, name, []

def __call__(self, label):
self.call("set %slabel '%s'" % (self.name, label))

self.call, self.name, self._range, self._label = \
call, name, [], None

def __getitem__(self, k):
if isinstance(k, slice):
Expand All @@ -44,6 +41,16 @@ def get_range(self):
range = property(get_range, set_range)


def set_label(self, label):
self._label = label
self.call("set %slabel '%s'" % (self.name, label))

def get_label(self):
return self._label

label = property(get_label, set_label)


class MultiPlot(object):
def __init__(self, nplot, session, **kwargs):
self.session = ref(session)()
Expand Down

0 comments on commit fa534b5

Please sign in to comment.