Posts about ipython (old posts, page 2)

2015-02-17 Creating an animation using Gizeh + MoviePy

Gizeh (that is, Cairo for tourists) is a great interface to the Cairo drawing library.

I recently wished to make a small animation of a bar moving in the visual field and crossing a simple receptive field to illustrate some simple motions that could be captured in the primary visual cortex ansd experiments that could be done there.

Read more…

Comments

2015-01-20 Using Tikzmagic

TIKZ is a great language for producing vector graphics. It is however a bit tedious to go over the whole $\LaTeX$-like compilation when you get used to an ipython notebooks work-flow.

I describe here how to use a cell magic implemented by http://www2.ipp.mpg.de/~mkraus/python/tikzmagic.py and a hack to use euclide within the graph (as implemented in https://github.com/laurentperrinet/ipython_magics).

Read more…

Comments

2015-01-16 Rendering 3D scenes in python

The above snippet shows how you can create a 3D rendered scene in a few lines of codes (from http://zulko.github.io/blog/2014/11/13/things-you-can-do-with-python-and-pov-ray/):

In [1]:
import vapory

camera = vapory.Camera( 'location', [0, 2, -3], 'look_at', [0, 1, 2] )
light = vapory.LightSource( [2, 4, -3], 'color', [1, 1, 1] )
sphere = vapory.Sphere( [0, 1, 2], 2, vapory.Texture( vapory.Pigment( 'color', [1, 0, 1] )))

scene = vapory.Scene(camera = camera , # a Camera object
                     objects = [light, sphere], # POV-Ray objects (items, lights)
                     included = ["colors.inc"]) # headers that POV-Ray may need

# passing 'ipython' as argument at the end of an IPython Notebook cell
# will display the picture in the IPython notebook.
scene.render('ipython', width=900, height=500)
Out[1]:

Here are more details...

Read more…

Comments

2015-01-07 The right imports in a notebook

Following this post http://carreau.github.io/posts/10-No-PyLab-Thanks.ipynb.html, here is ---all in one single cell--- the bits necessary to import most useful libraries in an ipython notebook:

In [1]:
# import numpy and set the printed precision to something humans can read
import numpy as np
np.set_printoptions(precision=2, suppress=True)
# set some prefs for matplotlib
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams.update({'text.usetex': True})
fig_width_pt = 700.  # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27               # Convert pt to inches
fig_width = fig_width_pt*inches_per_pt  # width in inches
FORMATS = ['pdf', 'eps']
phi = .5*np.sqrt(5) + .5 # useful ratio for figures
# define plots to be inserted interactively
%matplotlib inline
#%config InlineBackend.figure_format='retina' # high-def PNGs, quite bad when using file versioning
%config InlineBackend.figure_format='svg'

Below, I detail some thoughts on why it is a perfect preamble for most ipython notebooks.

Read more…

Comments

2014-12-09 Polar bar plots

I needed to show prior information for the orientation of contours in natural images showing a preference for cardinal axis. A polar plot showing seemed to be a natural choice for showing the probability distribution function. However, this seems visually flawed...

Read more…

Comments