Wednesday, September 10, 2014

How to make plots, images, 3D, etc, using Matplotlib

2014 Python Lecture. Part IV


This lecture is dedicated to the plotting library matplotlib. The topics are:


  • Simple plot
  • Controlling colors ans symbols
  • Overplot
  • Fixing axes limits
  • Labels, titles
  • Legends
  • The object oriented way to use Matplotlib
  • Scatter
  • log plots
  • Multiple plots
  • Everything is object
  • Error bars
  • Sharing axes
  • Histograms
  • Boxplots
  • Ticks, axes and spines
  • A plot inside a plot
  • Play with all the objects of a plot
  • Filled regions
  • 2D-histograms
  • 2D data sets and images
  • Contour
  • 3D scatter plots
  • Saving plots
  • Access and clear the current figure and axe
  • What's happen when not in a Notebook? plt.show() and plt.ion() commands
The lecture Notebook is there:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_Matplotlib.ipynb

Wednesday, September 3, 2014

Interacting with files: reading writing, ascii and fits

2014 Python lecture. Part III


It's time to play with files containing data! In this lecture, we'll see how to read and write files (ascii and fits).

  • Reading a simple ASCII file
  • How to treat special rows (comments, header)
    • classical way
    • using numpy.loadtxt
    • using numpy.genfromtxt
  • Dealing with missing data
  • Data in a fixed size format
  • Writing files
    • simple method
  • Pickle files (python format)
  • FITS files
The ipython notebook is there:

https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Interact%20with%20files.ipynb


Wednesday, August 20, 2014

Introduction to Numpy

2014 Python lecture. Part II


The introduction to Numpy can be seen here:
https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_numpy.ipynb

The topics that are presented are:

  • The Array class
    • create an array
    • 1D, 2D 3D arrays
    • creating array from scratch
    • arrays share memory (views)
  • random generator
  • timing a command
  • slicing arrays
  • assignments
  • using masks
  • the where function
  • some operations with arrays
  • broadcasting
  • calling scripts
  • structured arrays and record arrays
  • NaN other ANSI values.
Any comments are welcome.
Chris.Morisset a t Gmail.com

Wednesday, August 13, 2014

Python: Basics

2014 Python lecture. Part I


The introduction to Python I'm giving at IA-UNAM is accessible here:

https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/intro_Python.ipynb

I will modify this notebook during the lecture (August 2014), so reload it to have the latest version.

The topics of this first lecture are:
  • Using python as a calculator
  • assignments
  • comments
  • types
  • complex numbers
  • booleans
  • printing strings
  • strings
  • Tuples, lists and dictionaries
  • Blocks
  • List and dictionary comprehension
  • Functions, procedures
  • Scripting
  • Importing libraries
If you want to have an interactive session with this lecture using the ipython notebook facilities, follow the link above and download the ipynb file (download button at the right top of the web page). Save the file in a directory from where you execute the following (you must have a recent version of ipython installed):
ipython notebook
It should open a new tab in your web browser, with the list of ipynb files in the directory. Click on the one you want, will open a new tab similar to the first one, but this one is executed on YOUR computer, it means you are able to interact with the commands. You can change the commands, and execute a cell by SHIFT-ENTER. You can add comments in new cells, and save the result.

Any comments are welcome.

Thursday, August 7, 2014

Brief introduction to Python

2014 Python lecture. Part 0


Back to the Python lecture, I want to share here the very quick introduction I gave before starting to play with python: https://github.com/Morisset/Python-lectures-Notebooks/blob/master/Notebooks/Intro_1.pdf
You may want to install python from Ureka from this site: http://ssb.stsci.edu/ureka/

Wednesday, March 19, 2014

Using ipython Notebook to teach scientific python

A very good and efficient way to teach python and python related tools, is to use ipython Notebook: http://ipython.org/notebook.html

As example of this use, the following link is a collection of lectures on python, numpy, scipy, matplotlib, use of Fortran from python, etc:
https://github.com/jrjohansson/scientific-python-lectures
Enjoy them.

Friday, June 28, 2013

Installing python and nice lectures on scientific Python.

Since more than one year without any message!... And the new one is almost nothing from me, just links to good pages.

Two easy ways to install python+ipython+numpy+matplotlib+scipy:

Anaconda from continuum (but only 64bit version for OSX, which can be a problem for MySQLdb):
Ask for the academic licence if you can.
http://continuum.io/
Once installed, you will need to add the anaconda/bin directory to your PATH and the anaconda directory to your PYTHONPATH.

Canopy from Entought:
https://www.enthought.com/products/canopy/
Once installed, you must setup the virtual environment by adding to your .tcshrc:
setenv VIRTUAL_ENV /Users/YOURNAME/Library/Enthought/Canopy_32bit/User
setenv PATH  $VIRTUAL_ENV/bin:$PATH

!!! Warning !!! When using this virtual environment, don't install using pip with the --user option. Install directly, as for example:
pip install pyfits

UPDATE: Another (better) package comes from STSCI, it's UREKA: http://ssb.stsci.edu/ureka/

Here follows good pages to learn python. Those pages are made using Notebook, which is very efficient to show/share python programs.

Here are the links:

http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-0-Scientific-Computing-with-Python.ipynb
http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-1-Introduction-to-Python-Programming.ipynb
http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-2-Numpy.ipynb
http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-3-Scipy.ipynb
http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-4-Matplotlib.ipynb
http://nbviewer.ipython.org/urls/raw.github.com/jrjohansson/scientific-python-lectures/master/Lecture-6B-HPC.ipynb