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

Add myAxes_client

should be ok like that, let's see.
parent 9f42d865
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v3.0.1,
#
# @file myAxes.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyAxes class: Overlay of matplotlib Axes class
# It is done such that the user can concentrate on
# the important aspect of the figure and not the
# technical part. It consists of a constructor,
# that requires a Figure, the ratio of the xaxis over
# the yaxis, and the frame in which the figure
# should be plotted.
#
# @Class MyAxes
#
# @Constructor(self, fig, ratio, frame, +user defined kw):
#
# @section Functions
#
# - plotting: this is the overwritten function
# from Axes. It is called by it's
# parent-figure's function .plot()
#
# - formatRawData: it computes out of the rawData
# given as argument some quantities that
# are returned as a dictionary and
# become accessable for plotting.
#
# @section History
#
# v 0.0.0 - MyAxes class for the myplotlib module, consists
# of a constructor, a pltting function and
# formatRawData.
#
# v 2.2.3 - Add testRawData function
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from . import SEVR, DBUG
from . import Axes
from . import rcParams
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
self.declareKeywords()
rect = self.computeRect(ratio, frameRect, *args, **kwargs)
kwargs.pop('forceRatioOnWidth', None)
kwargs.pop('forceRatioOnHeight', None)
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
# set a default name. Should be individualized by instance
self.name = 'default'
# COMPUTE RECT -------------------------------------------------------
def computeRect(self, ratio, frameRect, *args, **kwargs):
# Get the optional keyword
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()
if(forceRatioOnWidth):
frameWidth = ratio * figWidth / (frameHeight * figHeight)
elif(forceRatioOnHeight):
frameHeight = ratio * (frameWidth * figWidth) / figHeight
rect = [framePosX, framePosY, frameWidth, frameHeight]
return(rect)
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
self.keywords = {}
# PLOTTING -----------------------------------------------------------
def plotting(self):
return(True)
# UPDATE -------------------------------------------------------------
def update(self, *args, **kwargs):
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!!)
if args: # catch matplotlib kwargs
kwargs = args[0]
# kw_for_axes = {key: value for (key, value) in args[0].items() if key not in self.keywords} # Not compatible with python2.6
kw_for_axes = {}
for (key, value) in args[0].items():
if key not in self.keywords:
kw_for_axes.update({key: value})
Axes.update(self, kw_for_axes) # update matplotlib.Axes
# myplotlib update
# self.keywords.update({key: value for (key, value) in kwargs.items() if key in self.keywords}) # Not compatible with python2.6
for (key, value) in kwargs.items():
if key in self.keywords:
self.keywords.update({key: value})
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