Commit 3ca89089 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

add axPlot2D, axPlots2D classes in myTool

see usage in tests, test509, test510, test511
tested and valid
parent fb67c64e
......@@ -86,7 +86,7 @@ from .mytool import window_exists, getCurrentWindowIDs
from .mytool import print2file, print2screen, printListCurrentWindows
from .mytool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .mytool import closeWindow, closeAllWindows
from .mytool import FigOneAxes_base, FigOneAxes2D, FigOneAxes3D
from .mytool import FigOneAxes
from .test import myTest
......@@ -98,7 +98,7 @@ from .test import test306, test307, test308, test309, test310
from .test import test400, test401, test402, test403
from .test import test500, test501, test502, test503, test504
from .test import test505, test506, test507, test508, test509
from .test import test510
from .test import test510, test511
from .test import test600
# the tests to run
......@@ -108,6 +108,6 @@ testList = [test100,
test306, test307, test308, test309, test310,
test400, test401, test402,
test503, test506, test500, test507, test501, test502,
test504, test505, test508, test509, test510,
test504, test505, test508, test509, test510, test511,
test600,
]
......@@ -11,7 +11,6 @@ from .myTool import drawFigOnWindow
from .myTool import closeAllWindows
from .myTool import closeWindow
from .figOneAxes_base import FigOneAxes_base
from .figOneAxes2D import FigOneAxes2D
from .figOneAxes3D import FigOneAxes3D
from .figOneAxes import FigOneAxes
from .axPlot2D import AxPlot2D
from .axPlots2D import AxPlots2D
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxPlot2D(MyAxes):
# DECLARE KEYWORDS --------------------------------------------------
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE,
'logx': D_LOGX,
'logy': D_LOGY}
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
# GET ALL PARAMETERS
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
logx = self.keywords.get('logx')
logy = self.keywords.get('logy')
xlabel = self.data.get('xlabel')
ylabel = self.data.get('ylabel')
xdata = self.data.get('xdata')
ydata = self.data.get('ydata')
# CHECK IF THE DATA EXISTS
if (xdata is None):
print(SEVR + "I need axes.data['xdata'] to plot... got None")
return(False)
if (ydata is None):
print(SEVR + "I need axes.data['ydata'] to plot... got None")
return(False)
# TRY TO PLOT
try:
# IF XLIN - YLIN
if (not logx) and (not logy):
self.plot(xdata, ydata)
# XLIN - YLOG
elif (not logx) and logy:
self.semilogy(xdata, ydata)
# XLOG - YLIN
elif (not logy) and logx:
self.semilogx(xdata, ydata)
# XLOG - YLOG
else:
self.loglog(xdata, ydata)
except:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
# SET THE LABELS
if (xlabel): self.set_xlabel(xlabel)
if (ylabel): self.set_ylabel(ylabel)
# SET THE RANGES
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
return(True)
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
from itertools import repeat
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxPlots2D(MyAxes):
# DECLARE KEYWORDS --------------------------------------------------
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE,
'logx': D_LOGX,
'logy': D_LOGY}
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
# GET ALL PARAMETERS
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
logx = self.keywords.get('logx')
logy = self.keywords.get('logy')
xlabel = self.data.get('xlabel')
ylabel = self.data.get('ylabel')
labels = self.data.get('labels', repeat(None))
xdata = self.data.get('xdata')
ydatas = self.data.get('ydatas')
# CHECK IF THE DATA EXISTS
if (xdata is None):
print(SEVR + "I need axes.data['xdata'] to plot... got None")
return(False)
if (ydatas is None):
print(SEVR + "I need axes.data['ydatas'] to plot... got None")
return(False)
# TRY TO PLOT
try:
# IF XLIN - YLIN
if (not logx) and (not logy):
for ydata, label in zip(ydatas, labels):
self.plot(xdata, ydata, label=label)
# XLIN - YLOG
elif (not logx) and logy:
for ydata, label in zip(ydatas, labels):
self.semilogy(xdata, ydata, label=label)
# XLOG - YLIN
elif (not logy) and logx:
for ydata, label in zip(ydatas, labels):
self.semilogx(xdata, ydata, label=label)
# XLOG - YLOG
else:
for ydata, label in zip(ydatas, labels):
self.loglog(xdata, ydata, label=label)
except:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
# SET THE LABELS
if (xlabel): self.set_xlabel(xlabel)
if (ylabel): self.set_ylabel(ylabel)
# SET THE RANGES
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
self.legend(bbox_to_anchor=(0.03, 0.97), loc=2, borderpad=0.5, prop={'size': 14})
return(True)
......@@ -10,7 +10,7 @@ class FigOneAxes(MyFig):
FIGSIZE = (8., 6.)
# CONSTRUCTOR -----------------------------------------------------
def __init__(self, rawdata, AxClass, *args, **kwargs):
def __init__(self, AxClass, rawdata, *args, **kwargs):
self.AxClass = AxClass
......
from .myIOs import readStupidData, readStupidData2
from .axTest1 import AxTest1
from .axTest1 import AxTest1, AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest2
from .tests import myTest
......@@ -13,6 +13,6 @@ from .tests import test306, test307, test308, test309, test310
from .tests import test400, test401, test402, test403
from .tests import test500, test501, test502, test503, test504
from .tests import test505, test506, test507, test508, test509
from .tests import test510
from .tests import test510, test511
from .tests import test600
......@@ -44,6 +44,7 @@
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
from ..mytool import AxPlot2D, AxPlots2D
D_XRANGE = None
D_YRANGE = None
......@@ -98,16 +99,7 @@ class AxTest1(MyAxes):
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest2D(MyAxes):
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE,
'logx': D_LOGX,
'logy': D_LOGY}
return(True)
class AxTestPlots2D(AxPlots2D):
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
......@@ -116,7 +108,12 @@ class AxTest2D(MyAxes):
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
'ydatas': ([rawdata.data[2], rawdata.data[3]],
[rawdata.data[3], rawdata.data[2]]),
'xlabel': 'Some X Label',
'ylabel': 'Some Y Label',
'labels': ('curve 1', 'curve 2')}
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
......@@ -125,21 +122,27 @@ class AxTest2D(MyAxes):
print(DBUG + 'I formatted the raw data!')
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlot2D(AxPlot2D):
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.plot(self.data['xdata'], self.data['ydata'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]],
'xlabel': 'Some X Label',
'ylabel': 'Some Y Label'}
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
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)
......@@ -6,14 +6,14 @@ from .. import SEVR, WARN, DBUG, SPCE
from .. import G_RAWDATAS, _G_WINDOWS
from . import readStupidData, readStupidData2
from . import FigTest2, AxTest1
from . import FigTest2, AxTest1, AxTestPlot2D, AxTestPlots2D
from .. import window_exists, getCurrentWindowIDs
from .. import getFigOnWindow, getWindow
from .. import closeWindow, closeAllWindows
from .. import print2screen, print2file, printListCurrentWindows
from .. import drawFigOnWindow, giveDataToWindow
from .. import FigOneAxes2D, FigOneAxes3D
from .. import FigOneAxes
# TESTER
......@@ -861,28 +861,42 @@ def test508(debug):
return(status)
# TEST 5.09: FigOneAxes2D
# TEST 5.09: FigOneAxes
def test509(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes2D(AxTest2D, (data1,))
fig = FigOneAxes(AxTest1, (data1,))
status = fig.plot()
return(status)
# TEST 5.10: FigOneAxes3D
# TEST 5.10: AxTestPlot2D
def test510(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes3D(AxTest3D, (data1,))
fig = FigOneAxes(AxTestPlot2D, (data1,))
status = fig.plot()
return(status)
# TEST 5.11: AxTestPlots2D
def test511(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes(AxTestPlots2D, (data1,))
status = fig.plot()
......
Supports Markdown
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