ipython cheat sheet
- Inline Pylab. Add this block to move to the directory of your choice and plot images inline.
%pwd
%cd C:\Users\Tasif\Dropbox\lab\dektak\2015_07_10_electrodes_paper
%pylab inline
- Open File with File Dialog on Top. Usually, file dialog box stays behind open applications. Use this to get it at the front.
# open file
import Tkinter, tkFileDialog
root = Tkinter.Tk() # make a top-level instance and hide since it is ugly and big.
root.withdraw()
root.overrideredirect(True) # make it almost invisible - no decorations, 0 size, top left corner.
root.geometry('0x0+0+0')
root.deiconify() # show window again and lift it to top so it can get focus,
root.lift() # otherwise dialogs will end up behind the terminal.
root.focus_force()
fname1 = tkFileDialog.askopenfilename(parent=root)
fname1_blank1 = str(fname1).replace(".txt", "")
fname1_blank2 = fname1_blank1.replace(".csv", "")
root.destroy() # get rid of the top-level instance once to make it actually invisible.
- Load Data from CSV File
data = np.genfromtxt(fname1, delimiter=',', skip_header=37,skip_footer=5)
scan_length = data[:,0];
height = data[:,1]/1000;
- Save Figure
fig = plt.figure()
plt.show()
fig.savefig(fname1_blank2+'_plot.png', dpi=600, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches='tight', pad_inches=0.25,
frameon=None)
- To change the home directory for ipython in Ubuntu. This can be used in the desktop launcher file - ipython.desktop located at /usr/share/applications. Usually, the default directory is /home.
ipython notebook '--NotebookManager.notebook_dir=/home/yasser/Dropbox/ipython'
- It took me a while to figure out how to install mayavi for IPython in Windows. If you’re using Anaconda distribution life will be easy.
- Open Anaconda Command Prompt from the start menu.
- Move to the Scripts directory under Anaconda.
cd Scripts
- Update conda
conda.exe update conda
- Install mayavi
conda.exe install mayavi
- Enable qt console by putting this at the beginning of your ipython notebook file
%gui qt
- Try out one of the examples provided here: http://docs.enthought.com/mayavi/mayavi/auto/examples.html#mlab-functions-gallery
Last modified: 2017-12-31