Tag Archives: python

Installing JPype to use Java from Python

JPype is a Python package that allows you to call Java from Python. First, download the zip file (I got version 0.5.4.2). I will use a virtual environment here, so the syntax is simply: cd /home/user/Downloads # path where the … Continue reading

Posted in Linux, Python | Tagged , , , | 4 Comments

PyQt4: example of TableWidget usage

The following simple example (inspired by saltycrane example shows how to build a simple application that pops up a table with PyQt4 and its TableWidget class. import sys from PyQt4.QtCore import * from PyQt4.QtGui import *   data = {’col1′:[’1′,’2′,’3’], … Continue reading

Posted in Python | Tagged , , | 3 Comments

nosetests: setup and teardown methods

nosetests is a tool used to build unit tests in python. Here below, I show an example on how to write a class that will perform some tests (test that a directory that has been created exists indeed). One issue … Continue reading

Posted in Python | Tagged , | Leave a comment

How to plot left and right axis with matplotlib

Sometimes, it is convenient to plot 2 data sets that have not the same range within the same plots. One will use the left y-axes and the other will use the right y-axis. With matplotlib, you need to create subplots … Continue reading

Posted in Python | Tagged , | 4 Comments

How to call R plotting function from python using rpy2

Python has already very good librairies from plotting (e.g., matplotlib, mayavi), however, it is sometimes useful to use some of the plotting functionalities offered by R. Thanks to the rp2 package, it is quite easy. Let us try to use … Continue reading

Posted in Python | Tagged , , | Leave a comment

How to embedded data files in python using setuptools

Within a Python package, it is useful to provide data files. These files are not python modules so you do not want to place same together with your module. Let us put them in a directory share/data. Suppose you have … Continue reading

Posted in Python | Tagged , | 8 Comments

installing rpy2 with different R version already installed

The easiest way to install a python package is to use easy_install (or pip), so to install rpy2, type: easy_install rpy2 To test that it is properly installed, type: import rpy2; from rpy2 import robjects; robjects.r(“version”) If this code works, … Continue reading

Posted in Computer Science, Linux, Python | Tagged , , , , | 8 Comments

python: how to flatten a nested list

Simple nested list of strings Suppose that you have a simple nested list. Simple in the sense that there is only one level: data = [[’a’,’b’], [’c’], [’d’]]data = [[‘a’,’b’], [‘c’], [‘d’]] you can use the operator module and reduce … Continue reading

Posted in Python | Tagged | Leave a comment

matplotlib: latex strings are not interpreted

If the LaTeX strings are not intepreted in matplotlib (e.g., in the xlabel), check your configuration file ( see previous post for matplotlib configuration file). You can either do it for one session : rc(’text’, usetex=True) plot([1,2],[3,4]); title(’a^2’) rc(‘text’, usetex=True) … Continue reading

Posted in Python | Tagged , | Leave a comment

Matplotlib configuration

Note 4/Sept/2013: the new location is /home/user/.config/matplotlib If you have ipython, try this command ipython -pylabipython -pylab and if you have Qt, you can change the backend (library used for plotting) and use qt as follows: ipython -pylab qtipython -pylab … Continue reading

Posted in Python | Tagged , | Leave a comment