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

New frame behaviour:

now the frame is not the one from the entire Axes, but just of the
bbox like in matplotlib.

I add two keywords, forceRatioOnHeight/Width these key words
ignores the Height/Width respectively and compute them
from the Width/Height and the ratio.

Since the ratio is not needed anymore it may be intersting to put it
as a optional keyword.

I am also thinking of one keywords:
FitEntireAxesInFrame, which would fit the entire pictures
(with axis labels, and ticks label, as well as centered in the frame)
parent 0f91bd65
......@@ -92,8 +92,8 @@ rc('lines', markersize=6)
rc('axes', linewidth=1.5)
rc('xtick.major', width=1.5, pad=10., size=10.)
rc('ytick.major', width=1.5, pad=8., size=10.)
rc('xtick.minor', width=1.5, size=5.)
rc('ytick.minor', width=1.5, size=5.)
rc('xtick.minor', width=1.5, size=5., visible=False)
rc('ytick.minor', width=1.5, size=5., visible=False)
rc('figure', dpi = 75.0)
# FUNCTIONS ------------------------------------------------------------
......
......@@ -56,6 +56,8 @@ class MyAxes(Axes):
self.fig = fig
rect = self.computeRect(ratio, frameRect, *args, **kwargs)
kwargs.pop('forceRatioOnWidth', None)
kwargs.pop('forceRatioOnHeight', None)
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
......@@ -65,58 +67,19 @@ class MyAxes(Axes):
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)
forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
# get the size of the figure
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
# 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(forceRatioOnWidth):
pass
rect = [framePosX, framePosY, frameHeight/ratio, frameHeight]
elif(forceRatioOnHeight):
pass
elif(forceRatioOnFigsize):
pass
rect = [framePosX, framePosY, frameWidth, frameWidth*ratio]
else:
rect = [framePosX, framePosY, frameWidth, frameHeight]
# 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)
# PLOTTING -----------------------------------------------------------
......
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