#!/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 --------------------------------------------------------------- from myplotlib import MplAxes from myplotlib import DBUG, SPCE, INFO, WARN, SEVR D_X_RANGE = None D_Y_RANGE = None D_LOG_Y = False D_LOG_X = False # Class MyAxes Overwriting Matplotlib.figure.Axes class AxTest(MplAxes): # DECLARE KEYWORDS ------------------------------------------------- def declare_keywords(self): self.keywords = {'x_range': D_X_RANGE, 'y_range': D_Y_RANGE} return(True) # FORMATTING ------------------------------------------------------- def format_rawdata(self, rawdata): # give value to data a dict # with xdata, ydata1, zdata, ydata2 ... try: self.data = {'x_data': [rawdata[0], rawdata[1]], 'y_data': [rawdata[2], rawdata[3]]} 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): x_range = self.keywords.get('x_range') y_range = self.keywords.get('y_range') try: self.plot(self.data['x_data'], self.data['y_data']) except KeyError: print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT') return(False) if (x_range): self.set_xlim(x_range) if (y_range): self.set_ylim(y_range) return(True) class AxBroken(MplAxes): def FormatRawdata(self, rawdata): return(True) def Plottting(self): return(True) class AxMinimumImplementation(MplAxes): def format_rawdata(self, rawdata): return(True) def plotting(self): return(True) class AxWithKeywords(MplAxes): def declare_keywords(self): self.keywords = {'x_range': [-1., 1.], 'y_range': [-1., 1.], 'title': None} def format_rawdata(self, rawdata): return(True) def plotting(self): title = self.keywords.get('title',None) if title: self.set_title(title) return(True)