Commit d2ddb4b8 authored by Yori Fournier's avatar Yori Fournier
Browse files

add a reference of the axes in Formatter, default is None, so it is not

required for creation neither importation but the user can access
Axes.keywords inside the method Formatter.shape.

This is usefull to pass dynamically keywords to the formatter.
parent ae48b751
Pipeline #486 passed with stage
in 4 minutes and 30 seconds
......@@ -13,6 +13,7 @@ from .myTool import closeWindow
from .figOneAxes import FigOneAxes
from .formatter import Formatter
from .formatter import FormatterListToLine
from .formatter import FormatterArrayToLines
from .formatter import FormatterAppendToLines
......
# IMPORT ---------------------------------------------------------------
from .. import MyAxes, SEVR, INFO
from .. import MyAxes, SEVR, INFO, WARN, SPCE
from . import FormatterListToLine
from itertools import repeat
......@@ -49,6 +49,7 @@ class Ax2dPlots(MyAxes):
def formatRawData(self, rawdata):
formatter = self.keywords.get('formatter', FormatterListToLine())
formatter.setAxes(self)
self.data = formatter.shape(rawdata)
return(True)
......@@ -85,13 +86,17 @@ class Ax2dPlots(MyAxes):
if labels == []:
labels = self.data.get('labels', repeat(None))
xdata = self.data.get('xdata')
xdata = self.data.get('xdata', None)
xdatas = self.data.get('xdatas', None)
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 (xdatas is None):
if (xdata is None):
print(SEVR + "I need at least axes.data['xdata'] to plot... got None")
return(False)
else:
xdatas = repeat(xdata)
if (ydatas is None):
print(SEVR + "I need axes.data['ydatas'] to plot... got None")
......@@ -109,12 +114,12 @@ class Ax2dPlots(MyAxes):
tick_formatter.set_powerlimits((0., 0.))
self.yaxis.set_major_formatter(tick_formatter)
for ydata, label, color, marker, linestyle in zip(ydatas, labels, colors, markers, linestyles):
for xdata, ydata, label, color, marker, linestyle in zip(xdatas, ydatas, labels, colors, markers, linestyles):
self.plot(xdata, ydata, label=label, color=color, marker=marker, linestyle=linestyle)
# XLIN - YLOG
elif (not logx) and logy:
for ydata, label, color, marker, linestyle in zip(ydatas, labels, colors, markers, linestyles):
for xdata, ydata, label, color, marker, linestyle in zip(xdatas, ydatas, labels, colors, markers, linestyles):
self.semilogy(xdata, ydata, label=label, color=color, marker=marker, linestyle=linestyle)
# XLOG - YLIN
......@@ -125,12 +130,12 @@ class Ax2dPlots(MyAxes):
tick_formatter.set_powerlimits((0., 0.))
self.yaxis.set_major_formatter(tick_formatter)
for ydata, label, color, marker, linestyle in zip(ydatas, labels, colors, markers, linestyles):
for xdata, ydata, label, color, marker, linestyle in zip(xdatas, ydatas, labels, colors, markers, linestyles):
self.semilogx(xdata, ydata, label=label, color=color, marker=marker, linestyle=linestyle)
# XLOG - YLOG
else:
for ydata, label, color, marker, linestyle in zip(ydatas, labels, colors, markers, linestyles):
for xdata, ydata, label, color, marker, linestyle in zip(xdatas, ydatas, labels, colors, markers, linestyles):
self.loglog(xdata, ydata, label=label, color=color, marker=marker, linestyle=linestyle)
except Exception as e:
......
......@@ -3,16 +3,20 @@ from itertools import repeat
class Formatter(object):
def __init__(self):
pass
self.axes = None
def shape(self, rawdata):
pass
def setAxes(self, axes):
self.axes = axes
class FormatterListToLine(Formatter):
def __init__(self, xlabel=None, ylabel=None):
Formatter.__init__(self)
self.xlabel = xlabel
self.ylabel = ylabel
......@@ -32,6 +36,9 @@ class FormatterListToLine(Formatter):
class FormatterArrayToLines(Formatter):
def __init__(self, xdataIndex=None, xlabel=None, ylabel=None):
Formatter.__init__(self)
self.xlabel = xlabel
self.ylabel = ylabel
self.xdataIndex = xdataIndex
......
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