Commit 0f91bd65 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

add a FigTest1 figure that has a diff FigSize than FigTest2. add the...

add a FigTest1 figure that has a diff FigSize than FigTest2. add the possibility to give forceRatioOn... keywords to MyAxes Objects.
parent 5360845d
......@@ -52,13 +52,30 @@ class MyAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
rect = self.computeRect(ratio, frameRect, *args, **kwargs)
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
# COMPUTE RECT -------------------------------------------------------
def computeRect(self, ratio, frameRect, *args, **kwargs):
# Get the optional keyword
forceRatioOnWidth = kwargs.get('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.get('forceRatioOnHeight', None)
forceRatioOnFigsize = kwargs.get('forceRatioOnFigsize', None)
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
# get the size of the figure
figWidth = fig.get_figwidth()
figHeight = fig.get_figheight()
figDpi = fig.get_dpi()
figWidth = self.fig.get_figwidth()
figHeight = self.fig.get_figheight()
figDpi = self.fig.get_dpi()
# get the font size in inches
fontsize = rcParams['font.size'] / figDpi
......@@ -72,27 +89,36 @@ class MyAxes(Axes):
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
if(forceRatioOnWidth):
pass
elif(forceRatioOnHeight):
pass
elif(forceRatioOnFigsize):
pass
else:
height = maxHeight / figHeight
width = hypoWidth / figWidth
posX = framePosX + (frameWidth - width) / 2.
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight
# 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]
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
return(rect)
self.fig = fig
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
......
from myIOs import readStupidData, readStupidData2
from axTest1 import AxTest1
from figTest import FigTest2
from figTest import FigTest2, FigTest1
from tests import myTest
......
......@@ -75,6 +75,28 @@ D_XRANGE = [-1, 1]
D_YRANGE = [-2, 2]
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest1(MyFig):
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (6., 8.)
def defineKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
return(True)
def addAxes(self):
ratio = 6. / 8. # height/width of the axes (in inch)
frame = [0.0, 0.0, 1.0, 1.0] # part of the fig that is available
self.add_axes(AxTest1(self, ratio, frame))
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest2(MyFig):
......
Markdown is supported
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