[Tutor] Plotting with python

Martin A. Brown martin at linux-ip.net
Sat Oct 31 01:57:39 EDT 2015


>> If you were going to get started doing some simple plotting with Python
>> 2.7 (in my case, I'm simply plotting temperature against time-of-day)
>> what would you use?
>>
>>  - matplotlib [1]
>>  - gnuplot [2]
>>  - something else entirely?
>>
>> Assume no substantial familiarity with the underlying plotting software,
>> let alone the Python bindings.
>>
>> The only thing I can think of that might be special is to specify the
>> upper/lower bounds of the plot; for example, in my case, I know the
>> temperatures vary between somewhere around 70-78 degrees F., so I'd want
>> the Y-axis to go, say 60-90, not arbitrarily start at zero; but I
>> suspect this is a pretty standard thing in almost any plotting package.
>>
>> [1] http://matplotlib.org/api/pyplot_api.html
>> [2] http://gnuplot-py.sourceforge.net/
>
> matplotlib, I gave up gnuplot in favour of it maybe 15 years ago and have never
> looked back.

I think my transition was later and I'm modestly bilingual with 
these tools.  However, in principle, I agree with Mark--IF you are 
primarily using Python as your tool for massaging and exploring 
data.

If you are, then I might add one more suggestion.  There's a project 
called 'IPython' [0] which has built a very nicely extended and 
richer interactive interface to the Python interpreter.  You can use 
IPython as a replacement for the Python interactive shell.  I have 
for years, and it's wonderful (even though, I also use the 
interactive shell that ships with the system supplied Python I use).

Why am I talking about IPython?  Aside from other benefits, the 
IPython Notebook [1] is directly useful to those who are also 
matplotlib users, because it allows you to record an entire analysis 
session, display graphics inline (see macro "%matplotlib inline") 
and then later, share the data explorations in a web browser.

N.B. I have not found any running, public IPython Notebooks.  This 
doesn't surprise me, because of the security risks of allowing just 
anybody access to a Python instance is like letting strangers into 
your kitchen.  They might eat all of your food, or try to crack that 
safe behind the portrait in the dining room.

  http://calebmadrigal.com/graph-ipython-notebook/

So, if I were in your shoes, starting today, I'd install IPython and 
matplotlib and then fire up the IPython Notebook on my local 
machine, type '%matplotlib inline' and start trying to display my 
data.  One nice feature of matplotlib is that it autoscales by 
default.  So, if all of your values (temperature) are within the 
range you want to display, you don't need to mess with the axes.

See their tutorial:

  http://matplotlib.org/users/pyplot_tutorial.html

Good luck and enjoy!

-Martin

 [0] http://ipython.org/
 [1] http://ipython.org/notebook.html

-- 
Martin A. Brown
http://linux-ip.net/


More information about the Tutor mailing list