Commit cfbbbda3 authored by Philipp Gast's avatar Philipp Gast
Browse files

added names to axis. getByName() and overloaded get_axes() to assign name.

BUG: two axes figure (test.figure3) shows only one axes
parent 60942fcf
......@@ -64,6 +64,9 @@ class MyAxes(Axes):
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
# set a default name. Should be individualized by instance
self.name='default'
# COMPUTE RECT -------------------------------------------------------
......
......@@ -74,6 +74,7 @@ from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN
from . import G_RAWDATAS
from . import MyData
from . import MyAxes
from . import Figure
......@@ -149,6 +150,8 @@ class MyFig(Figure):
# either a keywords or crap
else:
delete = False
# if it is an axes keyword
for ax in self.get_axes() :
......@@ -173,6 +176,33 @@ class MyFig(Figure):
def addAxes(self, *arg, **kwargs):
pass
# This overwrites MPL add_axes. It gives a name to the axis added so that it is easier to refer to
def add_axes(self, ax, name) :
if isinstance(name, basestring) and isinstance(ax, MyAxes):
ax.name = name
else:
print(SEVR + " there is an error with the input type of add_axes()")
return False
# test if an axes with that name is already present
for ax in self.get_axes() :
if ax.name == name :
print(SEVR + " an axes with that name is already present")
return False
Figure.add_axes(self, ax)
return True
def getAxesByName(self, name):
for ax in self.get_axes() :
if ax.name == name :
return ax
else :
return None
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
......
......@@ -2,6 +2,7 @@ from .myIOs import readStupidData, readStupidData2
from .axTest1 import AxTest1
from .figTest import FigTest2
from .figTest import FigTest3
from .tests import myTest
......
......@@ -108,3 +108,31 @@ class FigTest2(MyFig):
frame1 = [0.1, 0.1, 0.8, 0.8] # part of the fig that is available
self.add_axes(AxTest1(self, ratio, frame1))
class FigTest3(MyFig):
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (8., 6.)
def addAxes(self):
ratio = 6. / 8. # height/width of the axes (in inch)
frame1 = [0.1, 0.1, 0.4, 0.8] # part of the fig that is available
frame2 = [0.6, 0.1, 0.4, 0.8] # part of the fig that is available
print(self.add_axes(AxTest1(self, ratio, frame1),"p1"))
print(self.add_axes(AxTest1(self, ratio, frame2),"p2"))
def declareAliases(self):
# it is important to not hold additional references to an axes in the figure to avoid memory leaks. use the this function
# get the plot added above
p1 = self.getAxesByName("p1")
p2 = self.getAxesByName("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
return(True)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment