Re: [Matplotlib-users] Subaxes deletion issue

2013-01-28 Thread Jae-Joon Lee
The divider thing from axes_grid toolkit is primarily designed for a static
layout. So, it may become quite tricky when you want to adjust the layout
dynamically.

Here is a modified version your code that I think does what you want.

from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import make_axes_locatable
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class Test(QWidget):
def __init__(self):
QWidget.__init__(self)
self.resize(1000, 600)
self.fig = Figure(figsize=(100,100), dpi=75)
axes1 = self.fig.add_subplot(121)
axes2 = self.fig.add_subplot(122)

self.subaxes = []
self.main_axes = [axes1, axes2]
self.locators_orig = []
for ax in [axes1, axes2]:
make_axes_locatable(ax)
self.locators_orig.append(ax.get_axes_locator())

self.divider = make_axes_locatable(ax)
self.subaxes.append(self.divider.append_axes(right, 40%,
20%))

b = QPushButton(Remove subaxes)
b.clicked.connect(self.OnBtnClicked)
l = QHBoxLayout()
l.addWidget(FigureCanvas(self.fig))
l.addWidget(b)
self.setLayout(l)

def OnBtnClicked(self):
for sa in self.subaxes:
self.fig.delaxes(sa)
del sa
for ax, locator in zip(self.main_axes, self.locators_orig):
ax.set_axes_locator(locator)
self.fig.canvas.draw()

app = QApplication(sys.argv)
win = Test()
win.show()
sys.exit(app.exec_())


IHTH,

-JJ




On Fri, Jan 18, 2013 at 6:57 AM, gad massi_...@msn.com wrote:

 Hi everyone,

 I'm getting in trouble trying to delete a couple of subaxes from my canvas.
 The problem is shown by the example script below:

 from matplotlib.figure import Figure
 from mpl_toolkits.axes_grid.axes_divider import make_axes_locatable
 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
 FigureCanvas
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 import sys

 class Test(QWidget):
 def __init__(self):
 QWidget.__init__(self)
 self.resize(1000, 600)
 self.fig = Figure(figsize=(100,100), dpi=75)
 axes1 = self.fig.add_subplot(121)
 axes2 = self.fig.add_subplot(122)

 self.subaxes = []
 for ax in [axes1, axes2]:
 self.divider = make_axes_locatable(ax)
 self.subaxes.append(self.divider.append_axes(right, 40%,
 20%))

 b = QPushButton(Remove subaxes)
 b.clicked.connect(self.OnBtnClicked)
 l = QHBoxLayout()
 l.addWidget(FigureCanvas(self.fig))
 l.addWidget(b)
 self.setLayout(l)

 def OnBtnClicked(self):
 for sa in self.subaxes:
 self.fig.delaxes(sa)
 del sa
 self.fig.canvas.draw()

 app = QApplication(sys.argv)
 win = Test()
 win.show()
 sys.exit(app.exec_())


 The main window is made up of two main axes an two subaxes placed on their
 right side. If you click the button in the window, the two subaxes
 disappear
 as I expect, but the orignal axes don't resize. Is there something I am
 missing? Or can anyone point me out if there is a better way to achieve
 this?

 Thanks in advance!



 --
 View this message in context:
 http://matplotlib.1069221.n5.nabble.com/Subaxes-deletion-issue-tp40268.html
 Sent from the matplotlib - users mailing list archive at Nabble.com.


 --
 Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
 MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
 with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
 MVPs and experts. ON SALE this month only -- learn more at:
 http://p.sf.net/sfu/learnmore_122712
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Subaxes deletion issue

2013-01-17 Thread gad
Hi everyone,

I'm getting in trouble trying to delete a couple of subaxes from my canvas.
The problem is shown by the example script below:

from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import make_axes_locatable
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class Test(QWidget):
def __init__(self):
QWidget.__init__(self)
self.resize(1000, 600)  
self.fig = Figure(figsize=(100,100), dpi=75)  
axes1 = self.fig.add_subplot(121)
axes2 = self.fig.add_subplot(122)

self.subaxes = []
for ax in [axes1, axes2]:
self.divider = make_axes_locatable(ax)
self.subaxes.append(self.divider.append_axes(right, 40%,
20%))

b = QPushButton(Remove subaxes)
b.clicked.connect(self.OnBtnClicked)
l = QHBoxLayout()
l.addWidget(FigureCanvas(self.fig))
l.addWidget(b)
self.setLayout(l)

def OnBtnClicked(self):
for sa in self.subaxes:
self.fig.delaxes(sa)
del sa
self.fig.canvas.draw()

app = QApplication(sys.argv)
win = Test()
win.show()
sys.exit(app.exec_())


The main window is made up of two main axes an two subaxes placed on their
right side. If you click the button in the window, the two subaxes disappear
as I expect, but the orignal axes don't resize. Is there something I am
missing? Or can anyone point me out if there is a better way to achieve
this?

Thanks in advance!



--
View this message in context: 
http://matplotlib.1069221.n5.nabble.com/Subaxes-deletion-issue-tp40268.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users