Hi,
I have attached a small example displaying a simple plot in a PyQt based
widget. If you start resizing the widget manually, the labels of the
axes as well as the title disappear from the plot window even for
moderately small window sizes.
Any suggestions on how I can fix this?
Best regards,
Mads
--
+-----------------------------------------------------+
| Mads Ipsen |
+----------------------+------------------------------+
| Gåsebæksvej 7, 4. tv | |
| DK-2500 Valby | phone: +45-29716388 |
| Denmark | email: [email protected] |
+----------------------+------------------------------+
import sys
from PyQt4 import QtGui
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg
import matplotlib.backends.qt4_editor.figureoptions as figureoptions
class Plot2D(QtGui.QWidget):
"""
2D Plot class based on a matplotlib canvas.
"""
def __init__(self, parent=None, testing=False):
# Initialize base class
QtGui.QWidget.__init__(self, parent)
# Set a layout
layout = QtGui.QVBoxLayout()
self.setLayout(layout)
# Widget to hold the canvas
self._plot_widget = QtGui.QWidget()
# Set up figure
self._figure = Figure()
self._canvas = FigureCanvasQTAgg(self._figure)
self._canvas.setParent(self._plot_widget)
# Add widgets to the layout
layout.addWidget(self._canvas)
# Draw somthing
self.axes = self._figure.add_subplot(111)
self.draw()
def draw(self):
"""
Redraws a figure. Added for unit testing purposes but may also be used for inspiration
on how to make a plot.
"""
import numpy
str = '1 2 3 4'
data = map(int, str.split())
x = range(len(data))
# clear the axes and redraw the plot anew
self.axes.clear()
self.axes.bar(
left=x,
height=data,
width=8.0/ 100.0,
align='center',
alpha=0.44,
picker=5)
t = numpy.arange(0.0, 3.0, 0.01)
s = numpy.sin(2*numpy.pi*t)
self.axes.plot(t, s, picker=5)
self.axes.set_title('This is a title')
self.axes.set_xlabel('Clock is ticking')
self.axes.set_ylabel('Time is running')
self._canvas.draw()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
widget = Plot2D()
widget.show()
sys.exit(app.exec_())
# qApp = QtGui.QApplication(sys.argv)
# aw = ApplicationWindow()
# aw.setWindowTitle("%s" % progname)
# aw.show()
# sys.exit(qApp.exec_())
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users