# TL;DR¶

Use the my_print command - created by the following code - to view ChIPS plots within the notebook. Note that the window.display preference setting is changed to False to avoid creating an actual ChIPS window, and the show_gui command is overwritten so that you don't accidentally start it up:

{.python}
from IPython.core.display import Image
import IPython.core.display as display

from pychips import *
from pychips.hlui import *

import tempfile
import os

set_preference('window.display', 'false')

def my_print(fname=None):
"Display the current ChIPS window in IPython as a PNG"
use_temp = False
if fname is None:
fname = tempfile.mkstemp(prefix='chips_temp', suffix='.png')[1]

# Get ChIPS to create a PNG of the current window
pychips.print_window(fname, 'clobber=true')
img = Image(filename=fname)
display.display_png(img)
if use_temp:
os.remove(fname)

def show_gui():
"It doesn't make too much sense to run the GUI from the notebook"
print("show_gui() has been disabled!")

# How do we get plots from ChIPS into the IPython notebook?¶

At the moment we have a somewhat hacky way to get ChIPS plots into the notebook, by requiring that the user enter a command - immaginatively called my_print:

In [1]:
# What do we need imported?
from pychips import *
from pychips.hlui import *

# and because it is generally useful
import numpy as np


To avoid ChIPS windows being created - i.e. X11 windows - we turn off the display setting.

In [2]:
set_preference('window.display', 'false')


Now we define the my_print command, which creates a PNG file in a temporary directory and then tells the notebook to display it:

In [3]:
from IPython.core.display import Image
import IPython.core.display as display

# Okay, pychips has been brought into the default namespace, but import it
# here to make this cell easier to copy and paste into other notebooks.
# Ideally there should be some simple module of helper routines such as this
# available in CIAO or the user's path.
#
import pychips

import tempfile
import os

def my_print(fname=None):
"Display the current ChIPS window in IPython as a PNG"
use_temp = False
if fname is None:
fname = tempfile.mkstemp(prefix='chips_temp', suffix='.png')[1]

# Get ChIPS to create a PNG of the current window
pychips.print_window(fname, 'clobber=true')
img = Image(filename=fname)
display.display_png(img)
if use_temp:
os.remove(fname)



Now to try it out:

In [4]:
x = np.arange(0, 10, 0.05)
y = 5 * (np.sin(x)*np.sin(x+0.1) * np.cos(x)*np.cos(x-0.2))


There is no screen output; we can use the info command to check that something was created:

In [5]:
info()

Out[5]:
Window [win1]
Frame [frm1]
Plot [plot1]   (0.15,0.15)  .. (0.90,0.90)
Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
Curve [crv1]
X Axis [ax1]
Y Axis [ay1]


How about some of the query routines in ChIPS?

In [6]:
get_curve()

Out[6]:
baddata = 1
depth = 100
err.caplength = 10
err.color = default
err.down = False
err.left = False
err.right = False
err.style = line
err.thickness = 1.0
err.up = False
id = None
limit.length = 0.0500000007451
limit.override = True
line.color = default
line.style = 1
line.thickness = 1.0
stem = None
symbol.angle = 0.0
symbol.color = default
symbol.fill = True
symbol.size = 5
symbol.style = 0
In [7]:
get_plot_range()

Out[7]:
[-0.49750000000000005,
10.447500000000002,
-0.13179887903811238,
1.6990891599618156]

In [8]:
my_print()


And the plot can be adjusted:

In [9]:
set_curve(['line.color', 'goldenrod'])
set_plot_aspect_ratio('fit')
set_frame(['bgcolor', 'cccccc'])
# Note that we use print() here since it's not the last command and I want to make sure
# the output is visible
print(info())
my_print()

Window [win1]
Frame [frm1]
Plot [plot1]   (0.15,0.15)  .. (0.90,0.90)
Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
Curve [crv1]
X Axis [ax1]
Y Axis [ay1]



Note that if you type in show_gui, the GUI window should appear - assuming you are not running things remotely - and let you adjust the plot properties. Similarly, if you do not change the window.display preference to False, then a ChIPS window will appear on screen. Neither are likely to be appropriate for note book use. If you keep on typing show_gui then you can try something like:

In [10]:
def show_gui():
"Stop show_gui from being used"
print("show_gui() has been disabled!")

show_gui()

show_gui() has been disabled!


If you do want a hard-copy plot then use print_window as normal, noting that the default working directory is the notebook location, unless you have changed it. You can find out where this is using:

{.python}
import os
os.getcwd()

or just

{.python}
pwd
In [11]:
print_window('example.png')