Commit 2e1aeaec authored by Yori's avatar Yori
Browse files

Change the behaviour of mpl_grid /!\ break compatibility

  - now grid.append_axes just append the axes in the grid not in the fig.
  - more transparance requires more lines.

Tested
parent 1716b937
Pipeline #731 failed with stage
......@@ -23,10 +23,8 @@ class Grid(object):
for grid in self.get_grids():
grid.layout()
def append_axes(self, ax, ax_label, rawdata):
def append_axes(self, ax):
self.items.append(ax)
self.fig.add_axes(ax, ax_label)
self.fig.set_rawdata(self.fig.rawdata + (rawdata,))
def append_grid(self, grid):
self.items.append(grid)
......
......@@ -19,8 +19,8 @@ class WeightedGrid(Grid):
else:
self.weights = weights
def append_axes(self, ax, ax_label, rawdata, weight=None, weights=None):
Grid.append_axes(self, ax, ax_label, rawdata)
def append_axes(self, ax, weight=None, weights=None):
Grid.append_axes(self, ax)
if weights is not None:
self.weights = weights
......
......@@ -29,25 +29,25 @@ class WeightedGridTestCase(unittest.TestCase):
def test_append_axes(self):
wgrid = WeightedGrid(margin=0.15, padding=0.05)
self.foo_fig.set_grid(wgrid)
wgrid.append_axes(self.foo_axes, 'foo_axes', self.rawdata)
wgrid.append_axes(self.foo_axes)
self.assertEqual(wgrid.weights, [1.])
wgrid.append_axes(self.foo_axes2, 'foo_axes2', self.rawdata)
wgrid.append_axes(self.foo_axes2)
self.assertEqual(wgrid.weights, [1., 1.])
def test_append_axes_with_weight(self):
wgrid = WeightedGrid(margin=0.15, padding=0.05)
self.foo_fig.set_grid(wgrid)
wgrid.append_axes(self.foo_axes, 'foo_axes', self.rawdata, weight=0.6)
wgrid.append_axes(self.foo_axes, weight=0.6)
self.assertEqual(wgrid.weights, [0.6])
wgrid.append_axes(self.foo_axes2, 'foo_axes2', self.rawdata, weight=0.4)
wgrid.append_axes(self.foo_axes2, weight=0.4)
self.assertEqual(wgrid.weights, [0.6, 0.4])
def test_append_axes_with_weights(self):
wgrid = WeightedGrid(margin=0.15, padding=0.05)
self.foo_fig.set_grid(wgrid)
wgrid.append_axes(self.foo_axes, 'foo_axes', self.rawdata)
wgrid.append_axes(self.foo_axes)
self.assertEqual(wgrid.weights, [1.])
wgrid.append_axes(self.foo_axes2, 'foo_axes2', self.rawdata, weights=[0.4, 0.6])
wgrid.append_axes(self.foo_axes2, weights=[0.4, 0.6])
self.assertEqual(wgrid.weights, [0.4, 0.6])
def test_append_grid(self):
......@@ -106,7 +106,7 @@ class HorizontalWeightedGridTestCase(unittest.TestCase):
self.foo_fig.set_grid(wgrid)
self.wgrid.append_axes(self.foo_axes, 'foo_axes', self.rawdata, weight=0.6)
self.wgrid.append_axes(self.foo_axes, weight=0.6)
self.wgrid.append_axes(self.foo_grid, weight=0.4)
def test_layout(self):
......@@ -124,7 +124,7 @@ class VerticalWeightedGridTestCase(unittest.TestCase):
self.foo_fig.set_grid(wgrid)
self.wgrid.append_axes(self.foo_axes, 'foo_axes', self.rawdata, weight=0.6)
self.wgrid.append_axes(self.foo_axes, weight=0.6)
self.wgrid.append_axes(self.foo_grid, weight=0.4)
def test_layout(self):
......
......@@ -26,8 +26,14 @@ def script(with_print=False):
# Create an Ax2dPlot
ax = Ax2dPlots(fig, xlabel=r'x-axis', ylabel=r'y-axis', formatter=formatter, logx=True)
# Add the axes into the figure
fig.add_axes(ax, 'ax1')
# Add the axes into the grid
fig.grid.append_axes(ax, 'ax1', rawdata)
fig.grid.append_axes(ax)
# Set the rawdata
fig.update(rawdata=(rawdata,))
# Layout the grid
fig.layout()
......
......@@ -28,9 +28,15 @@ def script(with_print=False):
# Create an Ax2dPlot
ax = Ax2dPlots(fig, xlabel=r'x-axis', ylabel=r'y-axis', formatter=formatter, logx=True, xlim=[0.3, 300.], legend=True, legend_pos='br', labels=[r'original', r'theoretical', r'data'])
# Add the axes into the Figure
fig.add_axes(ax, 'ax1')
# Add the axes into the grid
fig.grid.append_axes(ax, 'ax1', rawdata)
fig.grid.append_axes(ax)
# set the rawdata
fig.update(rawdata=(rawdata,))
# Layout the grid
fig.layout()
......
......@@ -44,8 +44,14 @@ def script(with_print=False):
colors=['r', 'g', 'b'],
linestyles=['--', '-', ''])
# Add the axes into the Figure
fig.add_axes(ax, 'ax1')
# Add the axes into the grid
fig.grid.append_axes(ax, 'ax1', rawdata)
fig.grid.append_axes(ax)
# Set rawdata
fig.update(rawdata=(rawdata,))
# Layout the grid
fig.layout()
......
......@@ -37,6 +37,13 @@ def script(with_print=False):
ax4 = Ax2dPlots(fig, formatter=formatter)
ax5 = Ax2dPlots(fig, formatter=formatter)
# Add axes to Figure
fig.add_axes(ax1, 'ax1')
fig.add_axes(ax2, 'ax2')
fig.add_axes(ax3, 'ax3')
fig.add_axes(ax4, 'ax4')
fig.add_axes(ax5, 'ax5')
hgrid1 = HorizontalWeightedGrid(margin=0., padding=0.05)
hgrid2 = HorizontalWeightedGrid(margin=0., padding=0.05)
......@@ -44,13 +51,16 @@ def script(with_print=False):
vgrid.append_grid(hgrid2, weight=0.3)
# Add the axes into the grid
hgrid1.append_axes(ax1, 'ax1', rawdata, weight=0.3)
hgrid1.append_axes(ax2, 'ax2', rawdata, weight=0.7)
hgrid1.append_axes(ax1, weight=0.3)
hgrid1.append_axes(ax2, weight=0.7)
hgrid2.append_axes(ax3, weight=0.7)
hgrid2.append_axes(ax4, weight=0.3)
hgrid2.append_axes(ax3, 'ax3', rawdata, weight=0.7)
hgrid2.append_axes(ax4, 'ax4', rawdata, weight=0.3)
vgrid.append_axes(ax5, weight=0.4)
vgrid.append_axes(ax5, 'ax5', rawdata, weight=0.4)
# Set rawdata
fig.update(rawdata=(rawdata, rawdata, rawdata, rawdata, rawdata))
# Layout the grid
fig.layout()
......
......@@ -37,6 +37,13 @@ def script(with_print=False):
ax4 = Ax2dPlots(fig, formatter=formatter)
ax5 = Ax2dPlots(fig, formatter=formatter)
# Add axes to Figure
fig.add_axes(ax1, 'ax1')
fig.add_axes(ax2, 'ax2')
fig.add_axes(ax3, 'ax3')
fig.add_axes(ax4, 'ax4')
fig.add_axes(ax5, 'ax5')
hgrid1 = HorizontalGrid(margin=0., padding=0.05)
hgrid2 = HorizontalGrid(margin=0., padding=0.05)
......@@ -44,13 +51,16 @@ def script(with_print=False):
fig.grid.append_grid(hgrid2)
# Add the axes into the grid
hgrid1.append_axes(ax1, 'ax1', rawdata)
hgrid1.append_axes(ax2, 'ax2', rawdata)
hgrid1.append_axes(ax1)
hgrid1.append_axes(ax2)
hgrid2.append_axes(ax3)
hgrid2.append_axes(ax4)
hgrid2.append_axes(ax3, 'ax3', rawdata)
hgrid2.append_axes(ax4, 'ax4', rawdata)
fig.grid.append_axes(ax5)
fig.grid.append_axes(ax5, 'ax6', rawdata)
# Set rawdata
fig.update(rawdata=(rawdata, rawdata, rawdata, rawdata, rawdata))
# Layout the grid
fig.layout()
......
......@@ -32,8 +32,14 @@ def script(with_print=False):
# Create 5 axes
ax1 = Ax2dPlots(fig, formatter=formatter, legend=True, legend_pos='br')
# Add axes into Figure
fig.add_axes(ax1, 'ax1')
# Add the axes into the grid
vgrid.append_axes(ax1, 'ax1', rawdata)
vgrid.append_axes(ax1)
# set rawdata
fig.update(rawdata=(rawdata,))
# Layout the grid
fig.layout()
......
......@@ -29,9 +29,8 @@ class TestGrid(unittest.TestCase):
def test_append_axes(self):
vgrid = VerticalGrid()
self.fig.set_grid(vgrid)
self.fig.grid.append_axes(self.ax1, "ax1", self.data)
self.fig.grid.append_axes(self.ax2, "ax2", self.data)
self.assertEqual(self.fig.axes, [self.ax1, self.ax2])
self.fig.grid.append_axes(self.ax1)
self.fig.grid.append_axes(self.ax2)
self.assertEqual(self.fig.grid.items, [self.ax1, self.ax2])
self.fig.layout()
......@@ -40,8 +39,7 @@ class TestGrid(unittest.TestCase):
self.fig.set_grid(vgrid)
vgrid2 = VerticalGrid()
self.fig.grid.append_grid(vgrid2)
self.fig.grid.append_axes(self.ax2, "ax2", self.data)
self.assertEqual(self.fig.axes, [self.ax2])
self.fig.grid.append_axes(self.ax2)
self.assertEqual(self.fig.grid.items, [vgrid2, self.ax2])
self.fig.layout()
......@@ -50,10 +48,9 @@ class TestGrid(unittest.TestCase):
self.fig.set_grid(vgrid)
hgrid = HorizontalGrid(margin=0.0, padding=0.1)
self.fig.grid.append_grid(hgrid)
self.fig.grid.get_item(0).append_axes(self.ax1, "ax1", self.data)
self.fig.grid.get_item(0).append_axes(self.ax2, "ax2", self.data)
self.fig.grid.append_axes(self.ax3, "ax3", self.data)
self.assertEqual(self.fig.axes, [self.ax1, self.ax2, self.ax3])
self.fig.grid.get_item(0).append_axes(self.ax1)
self.fig.grid.get_item(0).append_axes(self.ax2)
self.fig.grid.append_axes(self.ax3)
self.assertEqual(self.fig.grid.items, [hgrid, self.ax3])
self.assertEqual(self.fig.grid.get_item(0).items, [self.ax1, self.ax2])
self.fig.layout()
......
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