myAxes.py 3.28 KB
Newer Older
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
#   myplotlib v0.0.0,
#
#   @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.
#
41
42
#   v 2.2.3 - Add testRawData function
#
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
43
44
45
46
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
47
48
49
from . import SEVR, DBUG
from . import Axes
from . import rcParams
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
50
51
52
53


# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes(Axes):
54
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
55
    # CONSTRUCTOR --------------------------------------------------------
56
    def __init__(self, fig, ratio, frameRect, *args, **kwargs):
57
58
        
        self.fig = fig
59
        self.declareKeywords()
60
61
        
        rect = self.computeRect(ratio, frameRect, *args, **kwargs)
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
62
63
        kwargs.pop('forceRatioOnWidth', None)
        kwargs.pop('forceRatioOnHeight', None)
64
65
66
67
68
69
70
71
72
        
        # parent constructor
        Axes.__init__(self, fig, rect, **kwargs)
    
    
    # COMPUTE RECT -------------------------------------------------------
    def computeRect(self, ratio, frameRect, *args, **kwargs):
        
        # Get the optional keyword
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
73
74
        forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
        forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
75
        
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
76
77
        # get the frame allowed
        framePosX, framePosY, frameWidth, frameHeight = frameRect
78
79
        
        if(forceRatioOnWidth):
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
80
            rect = [framePosX, framePosY, frameHeight/ratio, frameHeight]
81
        elif(forceRatioOnHeight):
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
82
            rect = [framePosX, framePosY, frameWidth, frameWidth*ratio]
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
83
        else:
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
84
            rect = [framePosX, framePosY, frameWidth, frameHeight]
85
86
            
        return(rect)
87
88
89
    
    # DECLARE KEYWORDS -------------------------------------------------
    def declareKeywords(self):
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
90
        self.keywords = {}
91
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
92
93
    # PLOTTING -----------------------------------------------------------
    def plotting(self):
94
        return(True)
95
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
96
97
    # FORMATTING ---------------------------------------------------------
    def formatRawData(self, rawdata):
98
        return(True)
99
    
100
101
    # TESTING THE RAWDATA ------------------------------------------------
    def testRawData(self, rawdata):
102
        return(True)