Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
If I import matplot and plot a frame with an IPython console window open IPython goes crazy and seg faults my app. I tried configuring my matplotlibrc to use Qt4 as the backend but no joy :(. Not sure how to chase down why IPython is crashing. Im using the 1.0-dev build. and 1.2.1 of matplotlib Any Help?
import os
from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.frontend.qt.console.ipython_widget import IPythonWidget
from IPython.frontend.qt.kernelmanager import QtKernelManager
from IPython.frontend.qt.inprocess_kernelmanager import QtInProcessKernelManager
from IPython.kernel.zmq.ipkernel import Kernel
from IPython.kernel.inprocess.ipkernel import InProcessKernel
from IPython.lib import guisupport
def print_process_id():
print 'Process ID is:', os.getpid()
def main(arguments={}):
# Print the ID of the main process
app = guisupport.get_app_qt4()
# Create an in-process kernel
# >>> print_process_id()
# will print the same process ID as the main process
kernel = InProcessKernel(gui='qt4')
kernel_manager = QtInProcessKernelManager(kernel=kernel)
# Uncomment these lines to use a kernel on a separate process
# >>> import os; print os.getpid()
# will give a different process ID
#kernel = Kernel(gui='qt4')
#kernel_manager = QtKernelManager(kernel=kernel)
def stop():
control = RichIPythonWidget()
#control = IPythonWidget()
control.kernel_manager = kernel_manager
if __name__ == '__main__':
import sys
import console_ipython
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt
import random
from PyQt4.QtCore import QT_VERSION_STR
from PyQt4.pyqtconfig import Configuration
print("Qt version:", QT_VERSION_STR)
cfg = Configuration()
print("SIP version:", cfg.sip_version_str)
print("PyQt version:", cfg.pyqt_version_str)
class Window(QtGui.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QtGui.QPushButton('Plot')
# set the layout
layout = QtGui.QVBoxLayout()
def plot(self):
''' plot some random stuff '''
# random data
data = [random.random() for i in range(10)]
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
# plot data
ax.plot(data, '*-')
# refresh canvas
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Window()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment