-1

I am using Jupyter (with IPython) to analyze research data, as well as export figures. I really like the notebook approach offered by Jupyter: when I revisit an experiment after a long time, I can easily see how the figures correspond to the data. This is of course using the inline backend.

However, when I want to explore new data, I prefer to use the QT backend. It is faster than the inline one, and allows to easily scale, zoom in and out, and nicely displays the X and Y coordinates in the bottom left corner. Moreover, I can use the QT backend to determine good x and y limits to use in the inline backend.

I have tried using the %matplotlib notebook magic, but it is simply too slow. For some experiments I am plotting ~500 spectra (each consists of ~1000 data points), which is already slow in the inline backend. Even with less data points, the notebook backend is just too slow to use.

Therefore, I would like to use both the QT backend, and the inline backend whenever I plot something. (So, whenever I execute a cell which plots data, it should both display the inline image, and pop up a QT backend window). This way, I still have a nice overview of plots in my notebook, while also allowing me to easily explore my data. Is there a way to achieve this?

tcpie
  • 241
  • 3
  • 16

1 Answers1

0

This allows you to run QtConsole, plotting with the plotSin function, both inline and through the QtConsole.

import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline  

..

def plotChirp(Type, Exp, Rand):

    # Orignal Chirp Funciton From:
    # http://stackoverflow.com/questions/19410042/how-to-make-ipython-notebook-matplotlib-plot-inline
    x = np.linspace(0, 3*np.pi, Rand)
    plt.plot(x, np.sin(x**int(Exp)))
    plt.title('A simple chirp ' + Type)
    plt.show()

..

plotChirp("A", 5, 200) # Plots inline if you choose

enter image description here

%connect_info # For your own connection
%qtconsole

QtConsole opens and now you can call your function to plot externally..

enter image description here

Using %matplotlib qt allows for printing in a loop, but unfortunately it seems to overlap the plots. Looking into subplots as a possible solution.

%matplotlib qt
for i in range(0,2):

    if i == 0:
        plotChirp("B",1, 400)
    else:
        plotChirp("c",6, 1000)

enter image description here

Bob Hopez
  • 745
  • 3
  • 9
  • 24
  • Thank you for your answer. However, this is not the QT GUI window I was looking for. I want the same window that pops up when one uses `%matplotlib qt`, *not* the QT-console (which does not have the nice scaling, zooming and axis property changing capabilities of the other window). – tcpie Jun 30 '16 at 18:26
  • You may want to check out this post, as it allows for multiple plots to be scrolled through in QT Gui using a scroll though function: http://stackoverflow.com/questions/11563295/visualization-of-3d-numpy-array-frame-by-frame/11563414#11563414 – Bob Hopez Jul 05 '16 at 22:53
  • 1
    @tcpie i think this is what you are looking for https://stackoverflow.com/questions/41046299/pop-up-plots-using-python-jupyter-notebook it worked for me `%matplotlib tk` – mher Jan 02 '20 at 03:28