axes_tests.py 3.61 KB
Newer Older
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
41
42
43
44
45
#!/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.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------

46
from myplotlib import MplAxes
47
48
from myplotlib import DBUG, SPCE, INFO, WARN, SEVR

49
50
51
52
D_X_RANGE = None
D_Y_RANGE = None
D_LOG_Y = False
D_LOG_X = False
53
54
55


# Class MyAxes Overwriting Matplotlib.figure.Axes
56
class AxTest(MplAxes):
57
58

    # DECLARE KEYWORDS -------------------------------------------------
59
    def declare_keywords(self):
60
        
61
62
        self.keywords = {'x_range': D_X_RANGE,
                         'y_range': D_Y_RANGE}
63
64
65
66
        
        return(True)
  
    # FORMATTING -------------------------------------------------------
Yori Fournier's avatar
Yori Fournier committed
67
    def format_rawdata(self, rawdata):
68
69
70
71
     
        # give value to data a dict
        # with xdata, ydata1, zdata, ydata2 ...
        try:
72
73
            self.data = {'x_data': [rawdata[0], rawdata[1]],
                         'y_data': [rawdata[2], rawdata[3]]}
74
75
76
77
78
79
80
81
82
83
84
85
86
            
        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)
    
    def plotting(self):
        
87
88
        x_range = self.keywords.get('x_range')
        y_range = self.keywords.get('y_range')
89
90
        
        try:
91
            self.plot(self.data['x_data'], self.data['y_data'])
92
93
94
95
        except KeyError:
            print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
            return(False)
        
96
97
        if (x_range): self.set_xlim(x_range)
        if (y_range): self.set_ylim(y_range)
98
99
        
        return(True)
100

101

102
class AxBroken(MplAxes):
103
104
105
106
107
108
109

    def FormatRawdata(self, rawdata):
        return(True)

    def Plottting(self):
        return(True)

110

111
class AxMinimumImplementation(MplAxes):
112

113
    def format_rawdata(self, rawdata):
114
115
116
117
118
        return(True)
    
    def plotting(self):
        return(True)

119

120
class AxWithKeywords(MplAxes):
121

122
123
    def declare_keywords(self):
        self.keywords = {'x_range': [-1., 1.],
124
125
                         'y_range': [-1., 1.],
                         'title': None}
126

127
    def format_rawdata(self, rawdata):
128
129
130
        return(True)
        
    def plotting(self):
131
132
133
134
        title = self.keywords.get('title',None)
        if title:
            self.set_title(title)

135
        return(True)