Commit 567d4b84 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

mypltlib is now restructured with tests in test. I also changed MyFig and...

mypltlib is now restructured with tests in test. I also changed MyFig and MyAxes such that they can not be used alone. This is done such that now as seen in test figTest1 a figure consists only of an __init__ function. Nothing else is required. I also changed the refresh function of MyWins such that the figure does not destroy it axis but redraw them. So now the axes are create only ones. This has the side effect that when the window is resized the axes ratio is not respected anymore.
parent a2e6bd64
......@@ -48,7 +48,7 @@ from matplotlib import is_interactive
from matplotlib import rcParams
from matplotlib import use
rcParams['backend'] = u'TkAgg'
rcParams['backend'] = u'GTKAgg'
# myplotlib
from myData import MyData
......@@ -100,9 +100,6 @@ rc('figure', dpi = 75.0)
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes import MyAxes
# MyIOs.*: input/output function for testing
from .myIOs import readStupidData, readStupidData2
# MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig
......@@ -121,12 +118,6 @@ from .myTool import print2file, print2screen, printListCurrentWindows
from .myTool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .myTool import closeWindow, closeAllWindows
# MyFig4Test: Overlay of Figure for testing
from .myFig4Test import MyFig4Test
# some plotting routine for testing
from .myPlot4Test import somePlottingRoutine
from .test import myTest
from .test import test400, test300, test301, test302, test303, test304, test305, test306, test401, test402, test403
......
......@@ -51,9 +51,7 @@ from . import rcParams
class MyAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, **kwargs):
self.debug = kwargs.get('debug', 0)
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
......@@ -96,29 +94,8 @@ class MyAxes(Axes):
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
try:
self.plot(self.data['xdata'], self.data['ydata'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
return(True)
pass
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
except (TypeError, KeyError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.debug):
print(DBUG + 'I formatted the raw data!\n')
print(DBUG + 'formatted data:\n' + str(self.formattedDatas))
return(True)
pass
......@@ -70,7 +70,7 @@ from . import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED
from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN
from . import G_RAWDATAS
from . import Figure, MyAxes
from . import Figure
# Class MyFig Overwriting Matplotlib.figure.Figure
......@@ -118,6 +118,7 @@ class MyFig(Figure):
print(SPCE + " ID the figure: " + str(self.keywords['fignum']))
print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n')
# PLOT ---------------------------------------------------------------
def plot(self):
......@@ -127,14 +128,12 @@ class MyFig(Figure):
print(SEVR + "The dataset {dataName} does not exist. --> FALSE".format(dataName=self.keywords['inputarg']))
return(False)
ratio = 6. / 8. # height/width of the axes (in inch)
frame = [0.0, 0.0, 1.0, 1.0] # part of the fig that is available
# create an axes MyAxes with a given rect
ax = MyAxes(self, ratio, frame)
# For all axes in the figure reformat if needed and plot
for ax in self.get_axes():
# reformat the data if needed (default True)
if((self.keywords['reformat']) or (not self.keywords['formatted'])):
try:
status = ax.formatRawData(self.rawdata)
self.keywords['formatted'] = True
......@@ -142,17 +141,15 @@ class MyFig(Figure):
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
if(not status): return(False)
# add the axis to the figure
self.add_axes(ax)
# try to plot the Axes
# clean
ax.cla()
# plot
status = ax.plotting()
if(not status): return(False)
return(True)
# UPDATE -------------------------------------------------------------
def update(self, **kwargs):
......
......@@ -40,7 +40,7 @@ from . import INFO, SEVR, WARN, SPCE
from . import ion, ioff, is_interactive
from . import MyWin, MyFig
from . import MyWin
from . import np
......
......@@ -173,7 +173,6 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
self.set_figure(self.canvas.figure)
# refresh
self.canvas.figure.clf()
self.canvas.figure.plot()
self.canvas.draw()
......
......@@ -189,7 +189,6 @@ class MyWin_TkAgg(FigureManagerTkAgg):
self.set_figure(self.canvas.figure)
# refresh
self.canvas.figure.clf()
self.canvas.figure.plot()
self.canvas.draw()
......
......@@ -138,7 +138,6 @@ class MyWin_WXAgg(FigureManagerWx):
# if show is on, then show the window
if show:
self.canvas.figure.clf()
self.canvas.figure.plot()
self.show()
self.canvas.draw()
......@@ -187,7 +186,6 @@ class MyWin_WXAgg(FigureManagerWx):
self.set_figure(self.canvas.figure)
#refresh
self.canvas.figure.clf()
self.canvas.figure.plot()
self.canvas.draw()
self.canvas.figure.plot()
......
from myIOs import readStupidData, readStupidData2
from axTest1 import AxTest1
from figTest1 import FigTest1
from tests import myTest
from tests import test400, test300, test301, test302, test303, test304, test305, test306, test401, test402, test403
#!/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.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG
from .. import MyAxes
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest1(MyAxes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
# parent constructor
MyAxes.__init__(self, fig, ratio, frameRect, *args, **kwargs)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
try:
self.plot(self.data['xdata'], self.data['ydata'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
return(True)
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
except (TypeError, KeyError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.keywords['debug']):
print(DBUG + 'I formatted the raw data!\n')
print(DBUG + 'formatted data:\n' + str(self.fig.keywords['formatted']))
return(True)
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v1.0.1,
#
# @file myFig.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyFig class: Overlay of matplotlib Figure class
# It is done such that the user can concentrate on
# the important aspect of the figure and not the
# technical part.
#
# @Class MyFig
#
# @Constructor
#
# fignum: number of the Figure.
# inputarg: identifier of the raw data in G_RAWDATA.
# reformat: flag for reComputing plotted data
# from rawData.
# debug: flag for debugging, more verbatile.
# (kw)args: user defined arguments and keywords.
#
# @section Functions
#
# - printDebug: print some debug information.
#
# - plot: overlay of Figure.plot() function,
# should be overwrited by the user.
# Consists of
# - creating axes,
# - formating the data,
# - adding the axis to the figure
# - plotting the axis
#
# - update: update the parameters in the
# keywords dictionary.
#
# @section History
#
# v 0.1.1 - MyFig class for the myplotlib module.
#
# v 1.0.0 - Changed rawdata with inputarg to allows any type
# of rawdata, can be an array.
#
# replace the attribute format (reserved word) with
# formatted.
#
# v 1.0.1 - Suppress the explicit definitions of the keywords.
# by the introduction of the keywords dictionary.
# All parameters in this dictionary are automatically
# updated.
#
# suppress the default value of fignum and hardcode it
# to be -1.
#
# add the attribute boundedToWin required for the
# interactive mode of myplotlib.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from .. import os
from .. import DBUG, SEVR, INFO, SPCE, WARN
from .. import MyFig
from .axTest1 import AxTest1
D_XRANGE = [-1, 1]
D_YRANGE = [-2, 2]
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest1(MyFig):
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (8., 6.)
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, *args, **kwargs):
# parent constructor
MyFig.__init__(self, *args, **kwargs)
self.keywords.update({'xRange': D_XRANGE,
'yRange': D_YRANGE})
ratio = 6. / 8. # height/width of the axes (in inch)
frame = [0.0, 0.0, 1.0, 1.0] # part of the fig that is available
self.add_axes(AxTest1(self, ratio, frame, *args, **kwargs))
......@@ -29,10 +29,10 @@
#
#
# IMPORT ---------------------------------------------------------------
from . import DBUG
from . import D_IPATH
from . import MyData
from . import G_RAWDATAS
from .. import DBUG
from .. import D_IPATH
from .. import MyData
from .. import G_RAWDATAS
# READ STUPID DATA -----------------------------------------------------
......
from . import os
from . import D_OFORMAT, D_OPATH
from . import readStupidData, readStupidData2
from . import MyFig, MyWin
from . import SEVR, WARN, DBUG, SPCE
from . import _G_WINDOWS
from .. import os
from .. import D_OFORMAT, D_OPATH
from .. import MyFig, MyWin
from .. import SEVR, WARN, DBUG, SPCE
from .. import _G_WINDOWS
from . import readStupidData, readStupidData2
# TESTER
def myTest(function, expected, failed, debug):
......
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