Commit 4d8e9029 authored by Yori Fournier's avatar Yori Fournier
Browse files

Started to add some tutorials preparing mytool update

parent c7039757
Pipeline #450 passed with stage
in 3 minutes
......@@ -140,6 +140,10 @@ elif D_HIERARCHY in ('LOCAL', 'local'):
# MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig
from .empty_fig import EmptyFig
from .empty_axes import EmptyAxes
from .mplGrid import Grid, VerticalGrid, HorizontalGrid
else:
print(SEVR+'the value of D_HIERARCHY has to be SERVER, CLIENT or LOCAL')
......
from myplotlib import MyAxes
class EmptyAxes(MyAxes):
def plotting(self):
return(True)
def formatRawData(self, rawdata):
self.data = rawdata.data
return(True)
from myplotlib import MyFig
class EmptyFig(MyFig):
def __init__(self, **kwargs):
MyFig.__init__(self, (), **kwargs)
def addAxes(self):
pass
......@@ -42,9 +42,6 @@ class Grid(object):
class VerticalGrid(Grid):
def __init__(self, pos=_D_POS, margin=_D_MARGIN, padding=_D_PADDING):
Grid.__init__(self, pos=_D_POS, margin=margin, padding=padding)
def layout(self):
nbr_axes = len(self.items)
axes_height = (self.height - (nbr_axes-1)*self.padding - 2.*self.margin)/nbr_axes
......@@ -58,9 +55,6 @@ class VerticalGrid(Grid):
class HorizontalGrid(Grid):
def __init__(self, pos=_D_POS, margin=_D_MARGIN, padding=_D_PADDING):
Grid.__init__(self, pos=_D_POS, margin=margin, padding=padding)
def layout(self):
nbr_axes = len(self.items)
axes_width = (self.width - (nbr_axes-1)*self.padding - 2.*self.margin)/nbr_axes
......
......@@ -27,10 +27,12 @@
# ======================================================================
#
_D_NAME = 'default'
_D_DATA = None
class MyData():
def __init__(self):
def __init__(self, name=_D_NAME, data=_D_DATA):
self.name = 'default'
self.data = None
self.name = name
self.data = data
......@@ -11,10 +11,6 @@ from .myTool import drawFigOnWindow
from .myTool import closeAllWindows
from .myTool import closeWindow
from .grid import VerticalGrid
from .grid import HorizontalGrid
from .empty_fig import EmptyFig
from .figOneAxes import FigOneAxes
from .axPlot2D import AxPlot2D
from .axPlots2D import AxPlots2D
_D_GRID = None
from myplotlib import MyFig
from . import VerticalGrid
class InteractiveFig(object):
def appendAxes(self, axClass, rawdata):
ax = axClass(self, 1., [0.0, 0.0, 1.0, 1.0])
self.add_axes(ax, "ax"+str(len(self.axes)+1))
self.set_rawdata(self.rawdata + (rawdata,))
self.grid.layout()
def addVerticalGrid(self, **kwargs):
self.grid = VerticalGrid(self, **kwargs)
class EmptyFig(MyFig):
def __init__(self, **kwargs):
MyFig.__init__(self, (), **kwargs)
def addAxes(self):
pass
......@@ -5,8 +5,9 @@ import unittest
sys.path.append('../')
from myplotlib.mytool import *
# from myplotlib.mytool import *
from myplotlib import VerticalGrid, HorizontalGrid, EmptyFig
from myIOs import readStupidData
from figTest import FigTestWithAliases
from axTest import AxTest
......
......@@ -34,7 +34,7 @@ class TestMyAxes(unittest.TestCase):
self.assertEquals(ax.fig, self.fig)
self.assertEquals(ax.keywords, {})
self.assertEquals(ax.name, 'default')
self.assertEquals(ax.get_position().bounds, (0.1, 0.1, 0.9, 0.9))
self.assertEquals(ax.get_position().bounds, (0.1, 0.1, 0.8, 0.8))
def test_constructor_axwithkeywords(self):
'''Verify the keywords assignments of the constructor.
......
#!/usr/bin/env python
import sys
sys.path.insert(0, '../')
from myplotlib import MyData, EmptyFig, EmptyAxes
# read various data
rawdata = MyData(data=[0., 1., 0., 1.])
# make a figure
fig = EmptyFig()
# add an empty axes
fig.add_axes(EmptyAxes(fig), "ax1")
fig.set_rawdata((rawdata,))
# do some drawing
fig.axes[0].plot(fig.axes[0].data)
# print the figure with modif into a file
fig.print2file('./tuto000.png', as_seen=True)
#!/usr/bin/env python
import sys
sys.path.insert(0, '../')
from myplotlib import MyData, MyAxes, EmptyFig
class MySuperAxes(MyAxes):
def formatRawData(self, rawdata):
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
return(True)
def plotting(self):
self.plot(self.data['xdata'], self.data['ydata'])
return(True)
# read various data
rawdata = MyData(data=[0., 1., 0., 1.])
# make a figure
fig = EmptyFig()
# add an empty axes
fig.add_axes(MySuperAxes(fig), "ax1")
fig.set_rawdata((rawdata,))
# print the figure with modif into a file
fig.print2file('./tuto001.png')
#!/usr/bin/env python
import sys
sys.path.insert(0, '../')
from myplotlib import MyData, MyAxes, MyFig
class MySuperAxes(MyAxes):
def formatRawData(self, rawdata):
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
return(True)
def plotting(self):
self.plot(self.data['xdata'], self.data['ydata'])
return(True)
class MySuperFigure(MyFig):
def addAxes(self):
self.add_axes(MySuperAxes(self), "ax1")
# read various data
rawdata = MyData(data=[0., 1., 0., 1.])
# make a figure
fig = MySuperFigure((rawdata,))
# print the figure with modif into a file
fig.print2file('./tuto002.png')
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