Commit 60942fcf authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

merged and tested

- now keywords are added
parents 13f30740 5fe7eebb
......@@ -56,7 +56,6 @@ class MyAxes(Axes):
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
self.keywords={}
self.declareKeywords()
rect = self.computeRect(ratio, frameRect, *args, **kwargs)
......@@ -88,7 +87,7 @@ class MyAxes(Axes):
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
pass
self.keywords = {}
# PLOTTING -----------------------------------------------------------
def plotting(self):
......
......@@ -105,8 +105,8 @@ class MyFig(Figure):
self.boundedToWin = False
# initialise
kwargs.update({'rawdata': rawdata})
self._initialize(*args, **kwargs)
self.set_rawdata(rawdata)
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
......@@ -128,17 +128,17 @@ class MyFig(Figure):
# 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
if keyword in self._attributesToUpdateKeys:
elif keyword in self._attributesToUpdateKeys:
# update value
setattr(self, keyword, kwargs[keyword])
del rest[keyword]
# if it is the rawdata use the function
elif keyword == 'rawdata':
self.set_rawdata(kwargs['rawdata'])
del rest['rawdata']
# if aliases is defined with that name
elif keyword in self.aliases.keys():
# update
......@@ -146,9 +146,10 @@ class MyFig(Figure):
ax.keywords[key] = kwargs[keyword]
del rest[keyword]
# if it is an axes keyword
# either a keywords or crap
else:
# if it is an axes keyword
for ax in self.get_axes() :
if keyword in ax.keywords.keys():
......@@ -158,6 +159,7 @@ class MyFig(Figure):
if delete:
del rest[keyword]
# if there were some crap
if (self.debug and rest != {}) :
print(DBUG + "These keywords have not been updated: " + str(rest))
......@@ -182,9 +184,16 @@ class MyFig(Figure):
# DEFAULT: one item per axes in figure
if isinstance(rawdata, Iterable):
if(self.debug): print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
if len(rawdata) == len(self.get_axes()):
if(self.debug): print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
else:
self.rawdata = None
print(SEVR + "rawdata should have the dimention of the number of axes: #axes = " + str(len(self.get_axes())) + "; dim of rawdata = " + str(len(rawdata)))
return(False)
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MyData):
......@@ -198,6 +207,7 @@ class MyFig(Figure):
status = False
if not status:
print(SEVR + "set_rawdata: I could not set the rawdata...")
self.rawdata = None
return(status)
......@@ -205,7 +215,7 @@ class MyFig(Figure):
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
if self.rawdata != None:
if self.rawdata is not None:
for ax, rawdata in zip(self.get_axes(), self.rawdata):
......@@ -306,7 +316,10 @@ class MyFig(Figure):
# Plot the figure
if not as_seen:
self.plot()
status = self.plot()
if not status:
print(SEVR + 'Can not plot the figure. sorry --> EXIT')
return(False)
# draw the figure on the new canvas
canvas.draw() # not really needed (savefig does that)
......
......@@ -80,8 +80,8 @@ class AxTest1(MyAxes):
# the plotting function (need to be overwrite from child
def plotting(self):
xRange=self.keywords.get('xRange')
yRange=self.keywords.get('yRange')
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
try:
self.plot(self.data['xdata'], self.data['ydata'])
......@@ -93,4 +93,3 @@ class AxTest1(MyAxes):
if (yRange): self.set_ylim(yRange)
return(True)
......@@ -72,16 +72,39 @@ from .. import MyFig
from .axTest1 import AxTest1
class FigTest1(MyFig):
# 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
self.add_axes(AxTest1(self, ratio, frame1))
self.add_axes(AxTest1(self, ratio, frame2))
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest2(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)
frame = [0.1, 0.1, 0.8, 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, frame))
self.add_axes(AxTest1(self, ratio, frame1))
......@@ -255,7 +255,7 @@ def test301(debug):
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test301.png")
fig.print2file('test301.png', opath='myplotlib/img/') # create img/test301.png
status = fig.print2file('test301.png', opath='myplotlib/img/') # create img/test301.png
if not os.path.exists("./myplotlib/img/test301.png"):
status = False
......@@ -281,7 +281,7 @@ def test302(debug):
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test302.eps")
fig.print2file('test302.eps', opath='myplotlib/img/') # create img/test302.eps
status = fig.print2file('test302.eps', opath='myplotlib/img/') # create img/test302.eps
if not os.path.exists("./myplotlib/img/test302.eps"):
status = False
......@@ -327,7 +327,7 @@ def test304(debug):
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test304.eps")
fig.print2file('test304', oformat='.eps', opath='myplotlib/img/') # create img/test304.eps
status = fig.print2file('test304', oformat='.eps', opath='myplotlib/img/') # create img/test304.eps
if not os.path.exists("./myplotlib/img/test304.eps"):
status = False
......@@ -353,7 +353,7 @@ def test305(debug):
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test305.png")
fig.print2file('test305', oformat='png', opath='myplotlib/img/') # create img/test305.png
status = fig.print2file('test305', oformat='png', opath='myplotlib/img/') # create img/test305.png
if not os.path.exists("./myplotlib/img/test305.png"):
status = False
......@@ -379,7 +379,7 @@ def test306(debug):
if debug:
print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test306.png")
fig.print2file('myplotlib/img/test306.png') # create img/test306.png
status = fig.print2file('myplotlib/img/test306.png') # create img/test306.png
if not os.path.exists("./myplotlib/img/test306.png"):
status = False
......@@ -850,7 +850,7 @@ def test508(debug):
if debug:
print(DBUG + "Try to print FigTest2 with data1 in myplotlib/img/test508.png")
print2file(FigTest2, (data1,), "./myplotlib/img/test508.png")
status = print2file(FigTest2, (data1,), "./myplotlib/img/test508.png")
if not os.path.exists("./myplotlib/img/test508.png"):
status = False
......
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