Commit 81f0d2e7 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Merge branch 'move-keywords' into on-the-way-to-v3

parents d6ec1f25 c1866284
......@@ -94,7 +94,8 @@ from .test import myTest
from .test import test100
from .test import test200, test201, test202
from .test import test300, test301, test302, test303, test304, test305
from .test import test306, test307, test308, test309, test310
from .test import test306, test307, test308, test309, test310, test311
from .test import test312
from .test import test400, test401, test402, test403
from .test import test500, test501, test502, test503, test504
from .test import test505, test506, test507, test508, test509
......@@ -105,7 +106,8 @@ from .test import test600
testList = [test100,
test201, test202,
test300, test301, test302, test303, test304, test305,
test306, test307, test308, test309, test310,
test306, test307, test308, test309, test310, test311,
test312,
test400, test401, test402,
test503, test506, test500, test507, test501, test502,
test504, test505, test508, test509, test510, test511,
......
......@@ -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
......@@ -123,39 +124,34 @@ class MyFig(Figure):
# UPDATE ----------------------------------------------------------
def update(self, **kwargs):
rest = kwargs.copy()
# check attributes in keywords
for keyword in kwargs.keys():
# if it is the rawdata use the function
if keyword == 'rawdata':
self.set_rawdata(kwargs['rawdata'])
del rest['rawdata']
# if it is an attribute
elif keyword in self._attributesToUpdateKeys:
# update value
setattr(self, keyword, kwargs[keyword])
del rest[keyword]
# For each axes update the keywords
for ax in self.get_axes():
axrest = rest.copy() # make a copy of rest for this axes
axkwargs = kwargs.copy() # make a copy of kwargs for this axes
# Check if a key of rest has an alias for this axes
for krest in rest.keys():
if krest in self.aliases.keys():
alax, alkey = self.aliases[krest]
# Check if a key of kwargs has an alias for this axes
for axk in axkwargs.keys():
if axk in self.aliases.keys():
alax, alkey = self.aliases[axk]
# If an alias is found then update the rest
# If an alias is found then update axkwargs
if ax == alax:
axrest.update({alkey: rest[krest]})
axkwargs.update({alkey: kwargs[axk]})
# When eventual alias are added then update
ax.update(**axrest)
ax.update(**axkwargs)
return(True)
......@@ -167,6 +163,37 @@ 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 pax in self.get_axes() :
if pax.name == name :
print(SEVR + " an axes with that name is already present")
return False
Figure.add_axes(self, ax)
return True
# GET AXES BY NAME -------------------------------------------------
def getAxesByName(self, name):
for ax in self.get_axes() :
if ax.name == name :
return ax
#if the name is correct we should never get here.
print(SEVR + "The axes name ",name," was not found")
return None
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
......
......@@ -25,7 +25,7 @@ class FigOneAxes(MyFig):
smartFrame = self.computeSmartRect(ratio, frame)
self.add_axes(self.AxClass(self, ratio, smartFrame))
self.add_axes(self.AxClass(self, ratio, smartFrame), 'axes')
# Compute smart frame --------------------------------------------
def computeSmartRect(self, ratio, frameRect):
......
from .myIOs import readStupidData, readStupidData2
from .axTest1 import AxTest1, AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest2
from .axTest1 import AxTest1
from .axTest1 import AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest1, FigTest2
from .tests import myTest
......@@ -9,7 +10,8 @@ from .tests import myTest
from .tests import test100
from .tests import test200, test201, test202
from .tests import test300, test301, test302, test303, test304, test305
from .tests import test306, test307, test308, test309, test310
from .tests import test306, test307, test308, test309, test310, test311
from .tests import test312
from .tests import test400, test401, test402, test403
from .tests import test500, test501, test502, test503, test504
from .tests import test505, test506, test507, test508, test509
......
......@@ -71,32 +71,21 @@ from .. import MyFig
from .axTest1 import AxTest1
class FigTest1(MyFig):
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest1(MyFig): # Fig with one Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (8., 6.)
# def declareAliases(self):
# self.aliases = {'xRange_p1': (self.ax1, "xRange"),
# 'xRange_p2': (self.ax2, "xRange")}
# return(True)
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
frame1 = [0.1, 0.1, 0.8, 0.8] # part of the fig that is available
self.add_axes(AxTest1(self, ratio, frame1))
self.add_axes(AxTest1(self, ratio, frame2))
self.add_axes(AxTest1(self, ratio, frame1),"p1")
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest2(MyFig):
class FigTest2(MyFig): # Fig with two Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -105,6 +94,20 @@ class FigTest2(MyFig):
def addAxes(self):
ratio = 6. / 8. # height/width of the axes (in inch)
frame1 = [0.1, 0.1, 0.8, 0.8] # part of the fig that is available
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")}
self.add_axes(AxTest1(self, ratio, frame1))
return(True)
......@@ -6,7 +6,8 @@ from .. import SEVR, WARN, DBUG, SPCE
from .. import G_RAWDATAS, _G_WINDOWS
from . import readStupidData, readStupidData2
from . import FigTest2, AxTest1, AxTestPlot2D, AxTestPlots2D
from . import FigTest1,FigTest2, AxTest1
from . import AxTestPlot2D, AxTestPlots2D
from .. import window_exists, getCurrentWindowIDs
from .. import getFigOnWindow, getWindow
......@@ -82,10 +83,10 @@ def test200(debug):
data.data = [0, 0, 1, 1] # Dummy data
if(debug):
print(DBUG + "try to create FigTest2.")
print(DBUG + "try to create FigTest1.")
# create a figure
fig = FigTest2((data,), dpi=75.)
fig = FigTest1((data,), dpi=75.)
# set ratio and frameRect
ratio = 4. / 6. # float
......@@ -169,7 +170,7 @@ def test201(debug):
G_RAWDATAS.update({'data': MyData()})
# create the environment
fig = FigTest2((G_RAWDATAS['data'],))
fig = FigTest1((G_RAWDATAS['data'],))
# create the axis
ax = AxTest1(fig, 6. / 8., [0, 0, 1, 1])
......@@ -194,7 +195,7 @@ def test202(debug):
# create the environment
G_RAWDATAS.update({'data': MyData()})
fig = FigTest2((G_RAWDATAS['data'],))
fig = FigTest1((G_RAWDATAS['data'],))
# create the axis
ax = AxTest1(fig, 6. / 8., [0, 0, 1, 1])
......@@ -227,7 +228,7 @@ def test300(debug):
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
fig.update(rawdata=(data2,))
......@@ -251,7 +252,7 @@ def test301(debug):
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test301.png")
......@@ -277,7 +278,7 @@ def test302(debug):
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test302.eps")
......@@ -300,7 +301,7 @@ def test303(debug):
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "Try to print MyFig with data1 in a non existing file.")
......@@ -323,7 +324,7 @@ def test304(debug):
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test304.eps")
......@@ -349,7 +350,7 @@ def test305(debug):
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test305.png")
......@@ -375,7 +376,7 @@ def test306(debug):
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test306.png")
......@@ -403,7 +404,7 @@ def test307(debug):
# TEST 3.08: test MyFig::plot
def test308(debug):
fig = FigTest2(('Non-Existing-Data',), debug=False)
fig = FigTest1(('Non-Existing-Data',), debug=False)
if(debug):
print(DBUG + "test without data: ")
......@@ -450,7 +451,7 @@ def test309(debug):
status = True
fig = FigTest2(('dummy',), fignum=-12, reformat=True, debug=False, formatted=True)
fig = FigTest1(('dummy',), fignum=-12, reformat=True, debug=False, formatted=True)
if fig.fignum != -12:
status = False
......@@ -478,7 +479,7 @@ def test310(debug):
# create environment
data = readStupidData('data1')
fig = FigTest2((data,))
fig = FigTest1((data,))
# save current axis
ax = fig.get_axes()[0]
......@@ -495,6 +496,53 @@ def test310(debug):
return(status)
# TEST 3.11: test if the correct number of axes are present (EXPECTED: TRUE)
def test311(debug):
status = True
# create environment
data = readStupidData('data1')
fig = FigTest2(data) # use one4all method
if len(fig.get_axes()) != 2 : status=False # sounds like a stupid test but I had that problem :-S
return(status)
# TEST 3.12: test if alias behavior is correct (EXPECTED: TRUE)
def test312(debug):
status = True
# create environment
data = readStupidData('data1')
fig = FigTest2(data) # use one4all method
fig.update(xRange_p1=(0,2)) # using an alias
fig.update(yRange=(0,2)) # without using an alias
# update figure
fig.plot()
# get axes
ax1=fig.getAxesByName('p1')
ax2=fig.getAxesByName('p2')
print(data.data)
if ax1.get_xlim() != (0.0, 2.0) : status = False
if ax1.get_ylim() != (0.0, 2.0) : status = False
if ax2.get_xlim() != (-1.0, 1.0) : status = False
if ax2.get_ylim() != (0.0, 2.0) : status = False
if debug :
print(DBUG+'ax1 [x_min,xmax] : ', ax1.get_xlim())
print(DBUG+'ax1 [y_min,ymax] : ', ax1.get_ylim())
print(DBUG+'ax2 [x_min,xmax] : ', ax2.get_xlim())
print(DBUG+'ax2 [y_min,ymax] : ', ax2.get_ylim())
return(status)
# TEST 4.00: test MyWin (EXPECTED: TRUE)
def test400(debug):
......@@ -502,7 +550,7 @@ def test400(debug):
status = True
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
win = MyWin(fig)
try:
......@@ -527,7 +575,7 @@ def test401(debug):
# create figure
data1 = readStupidData('data1')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if debug:
print(DBUG + "An object MyFig with data1 has been created.")
......@@ -558,7 +606,7 @@ def test402(debug):
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
formerAxes = fig.get_axes()[0]
if(debug): print(DBUG + "Created a MyFig object with data1.")
......@@ -604,7 +652,7 @@ def test403(debug):
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
fig = FigTest2((data1,))
fig = FigTest1((data1,))
if(debug):
print(DBUG + "Put a MyFig into a MyWin with data1")
......@@ -639,7 +687,7 @@ def test503(debug):
status = True
data = readStupidData('data1')
fig = FigTest2((data,))
fig = FigTest1((data,))
win = MyWin(fig)
if(getFigOnWindow(0) != fig):
......@@ -658,7 +706,7 @@ def test506(debug):
status = True
data = readStupidData('data1')
fig = FigTest2((data,))
fig = FigTest1((data,))
win = MyWin(fig)
closeWindow(0)
......@@ -679,7 +727,7 @@ def test500(debug):
status = True
data = readStupidData('data1')
print2screen(FigTest2, (data,))
print2screen(FigTest1, (data,))
fig = getFigOnWindow(0)
if(fig.rawdata != (data,)):
status = False
......@@ -697,8 +745,8 @@ def test507(debug):
status = True
data = readStupidData('data1')
print2screen(FigTest2, (data,), fignum=1)
print2screen(FigTest2, (data,), fignum=4)
print2screen(FigTest1, (data,), fignum=1)
print2screen(FigTest1, (data,), fignum=4)
closeAllWindows()
......@@ -716,10 +764,10 @@ def test501(debug):
status = True
data = readStupidData('data1')
print2screen(FigTest2, (data,), fignum=1)
print2screen(FigTest2, (data,), fignum=24)
print2screen(FigTest2, (data,), fignum=4)
print2screen(FigTest2, (data,), fignum=1)
print2screen(FigTest1, (data,), fignum=1)
print2screen(FigTest1, (data,), fignum=24)
print2screen(FigTest1, (data,), fignum=4)
print2screen(FigTest1, (data,), fignum=1)
IDs = getCurrentWindowIDs()
......@@ -740,7 +788,7 @@ def test502(debug):
status = True
data = readStupidData('data1')
win = MyWin(FigTest2((data,)), fignum=2)
win = MyWin(FigTest1((data,)), fignum=2)
if(win != getWindow(2)):
status = False
......@@ -758,7 +806,7 @@ def test504(debug):
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
fig1 = FigTest2((data1,))
fig1 = FigTest1((data1,))
win = drawFigOnWindow(fig1, 12)
......@@ -774,7 +822,7 @@ def test504(debug):
status = False
if(debug): print(DBUG + "The canvas of fig1 is not the one of the window.")
fig2 = FigTest2((data2,))
fig2 = FigTest1((data2,))
if(win != drawFigOnWindow(fig2, 12)):
status = False
......@@ -814,7 +862,7 @@ def test505(debug):
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
print2screen(FigTest2, (data1,))
print2screen(FigTest1, (data1,))
giveDataToWindow((data2,), 0)
win = getWindow(0)
......@@ -850,8 +898,8 @@ def test508(debug):
data1 = readStupidData('data1')
if debug:
print(DBUG + "Try to print FigTest2 with data1 in myplotlib/img/test508.png")
status = print2file(FigTest2, (data1,), "./myplotlib/img/test508.png")
print(DBUG + "Try to print FigTest1 with data1 in myplotlib/img/test508.png")
status = print2file(FigTest1, (data1,), "./myplotlib/img/test508.png")
if not os.path.exists("./myplotlib/img/test508.png"):
status = False
......@@ -910,7 +958,7 @@ def test600(debug):
data = readStupidData('data1')
fig = FigTest2((data,))
fig = FigTest1((data,))
win = MyWin(fig)
......
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