Commit aae819e0 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

on the way to update mytool

- need FigOneAxes
- need FigMultiAxes
- need AxPlot2D
- need AxPlot3D
- need AxPlot4D
- need usage
parent 60942fcf
......@@ -97,7 +97,8 @@ from .test import test300, test301, test302, test303, test304, test305
from .test import test306, test307, test308, test309, test310
from .test import test400, test401, test402, test403
from .test import test500, test501, test502, test503, test504
from .test import test505, test506, test507, test508
from .test import test505, test506, test507, test508, test509
from .test import test510
from .test import test600
# the tests to run
......@@ -107,6 +108,6 @@ testList = [test100,
test306, test307, test308, test309, test310,
test400, test401, test402,
test503, test506, test500, test507, test501, test502,
test504, test505, test508,
test504, test505, test508, test509, test510,
test600,
]
# Import --------------------------------------------------------------
from .. import MyFig
from .. import rcParams
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes(MyFig):
# Set the size of the Figure in inch
FIGSIZE = (8., 6.)
# CONSTRUCTOR -----------------------------------------------------
def __init__(self, rawdata, AxClass, *args, **kwargs):
self.AxClass = AxClass
MyFig.__init__(self, rawdata, *args, **kwargs)
# ADD AXES --------------------------------------------------------
def addAxes(self):
ratio = self.FIGSIZE[1] / self.FIGSIZE[0]
frame = [0.0, 0.0, 1.0, 1.0]
smartFrame = self.computeSmartRect(ratio, frame)
self.add_axes(self.AxClass(self, ratio, smartFrame))
# Compute smart frame --------------------------------------------
def computeSmartRect(self, ratio, frameRect):
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
# get the size of the figure
figWidth = self.get_figwidth()
figHeight = self.get_figheight()
figDpi = self.get_dpi()
# get the font size in inches
fontsize = rcParams['font.size'] / figDpi
# the largest width and height allowed in inches
maxWidth = figWidth * frameWidth - 8. * (figDpi / 75.) * fontsize
maxHeight = figHeight * frameHeight - 4. * (figDpi / 75.) * fontsize
# the hypothetical width and height in inches
# for a given aspect ratio
hypoWidth = maxHeight / ratio
hypoHeight = maxWidth * ratio
# if the hypothetical width is larger that the
# maximum allowed width (in inches) then chose
# the hypothetical Height
if (hypoWidth > maxWidth):
height = hypoHeight / figHeight # height in percent
width = maxWidth / figWidth # width in percent
posX = framePosX + 4. * (figDpi / 75.) * fontsize / figWidth # posX
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight # posY
else:
height = maxHeight / figHeight
width = hypoWidth / figWidth
posX = framePosX + (frameWidth - width) / 2.
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight
rect = [posX, posY, width, height]
return(rect)
# Import --------------------------------------------------------------
from .figOneAxes_base import FigOneAxes_base
# Default values ------------------------------------------------------
_D_XRANGE = None
_D_YRANGE = None
_D_LOGX = False
_D_LOGY = False
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes2D(FigOneAxes_base):
# DECLARE kEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange' : _D_XRANGE,
'yrange' : _D_YRANGE,
'logx' : _D_LOGX,
'logy' : _D_LOGY}
# Import --------------------------------------------------------------
from .figOneAxes_base import FigOneAxes_base
# Default values ------------------------------------------------------
_D_XRANGE = None
_D_YRANGE = None
_D_ZRANGE = None
_D_LOGX = False
_D_LOGY = False
_D_LOGZ = False
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes3D(FigOneAxes_base):
# DECLARE kEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange' : _D_XRANGE,
'yrange' : _D_YRANGE,
'zrange' : _D_ZRANGE,
'logx' : _D_LOGX,
'logy' : _D_LOGY,
'logz' : _D_LOGZ}
# Import --------------------------------------------------------------
from .. import MyFig
# Default values ------------------------------------------------------
_D_XRANGE = None
_D_YRANGE = None
_D_LOG = False
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes_base(MyFig):
# Set the size of the Figure in inch
FIGSIZE = (8., 6.)
# CONSTRUCTOR -----------------------------------------------------
def __init__(self, rawdata, AxClass, *args, **kwargs):
self.AxClass = AxClass
MyFig.__init__(self, rawdata, *args, **kwargs)
# DECLARE kEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange' : _D_XRANGE,
'yrange' : _D_YRANGE,
'log' : _D_LOG}
# ADD AXES --------------------------------------------------------
def addAxes(self):
ratio = 6. / 8.
frame = [0.0, 0.0, 1.0, 1.0]
self.add_axes(self.AxClass(self, ratio, frame))
......@@ -12,6 +12,7 @@ from .tests import test300, test301, test302, test303, test304, test305
from .tests import test306, test307, test308, test309, test310
from .tests import test400, test401, test402, test403
from .tests import test500, test501, test502, test503, test504
from .tests import test505, test506, test507, test508
from .tests import test505, test506, test507, test508, test509
from .tests import test510
from .tests import test600
......@@ -47,6 +47,8 @@ from .. import MyAxes
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
......@@ -93,3 +95,51 @@ class AxTest1(MyAxes):
if (yRange): self.set_ylim(yRange)
return(True)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest2D(MyAxes):
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE,
'logx': D_LOGX,
'logy': D_LOGY}
return(True)
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.debug):
print(DBUG + 'I formatted the raw data!')
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
try:
self.plot(self.data['xdata'], self.data['ydata'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
return(True)
......@@ -13,6 +13,7 @@ from .. import getFigOnWindow, getWindow
from .. import closeWindow, closeAllWindows
from .. import print2screen, print2file, printListCurrentWindows
from .. import drawFigOnWindow, giveDataToWindow
from .. import FigOneAxes2D, FigOneAxes3D
# TESTER
......@@ -860,6 +861,34 @@ def test508(debug):
return(status)
# TEST 5.09: FigOneAxes2D
def test509(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes2D(AxTest2D, (data1,))
status = fig.plot()
return(status)
# TEST 5.10: FigOneAxes3D
def test510(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes3D(AxTest3D, (data1,))
status = fig.plot()
return(status)
# TEST 600: Test Adding Axes on the Fly (EXPECTED: True)
def test600(debug):
......
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