Discussion:
[SciPy-User] getting started with arrays and matplotlib
Chris Withers
2011-08-07 21:22:19 UTC
Permalink
Hi All,

I'm a new user returning to SciPy after quite a long break, so, a few
high-level questions first:

- Are there any good books or other narrative docs that cover the bulk
of the core numpy stuff

- Ditto, but for visualisation, particularly with matplotlib or the
Enthought visualisation suites.

I'm particularly interested in step-by-step docs/books with lots of
examples, versus reference docs that basically need the user to know
what they're looking for in a chicken and egg fashion, which was my
previous experience of scipy docs...

Now, the specific problem I'm looking to solve it a stacked bar chart of
ticket sales for an event over time. The data I have is basically a log
file of ticket sales.

I was looking to build a 4-dimensonal array as follows, with each cell
representing ticket sales for that week at that venue at that event:

event: 2011

venue t-3 week t-2 week t-1 week
v1 10 20 30
v2 15 30 45

event: 2010

venue t-3 week t-2 week t-1 week
v1 1 2 3
v2 15 30 45

...etc...

Now, first question: what's the best way to build this array given that
I may only see the arrival of a new venue a fair way through building
the data structure? How can I efficiently say "please add a new row to
my array", I don't know what the 4th dimension equivalent is ;-)

Secondly, once I've populated this, any good examples of how to turn it
into a bar chart? (the simple bar chart would be number of sales on the
y-axis, weeks before the event on the x-axis, however, what I'd then
like to do is split each bar into chunks for each venue's sales, if that
makes sense?)

Any help gratefully received!

cheers,

Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
David Warde-Farley
2011-08-08 05:29:44 UTC
Permalink
Post by Chris Withers
Now, first question: what's the best way to build this array given that
I may only see the arrival of a new venue a fair way through building
the data structure? How can I efficiently say "please add a new row to
my array", I don't know what the 4th dimension equivalent is ;-)
It may be worth thinking about whether an ndarray is necessarily the right way to solve this problem. For one thing, you can't append to ndarrays easily. HDF5 tables (via PyTables, for example) are more forgiving in this respect and play nice with NumPy, but there are certainly other options.
Post by Chris Withers
Secondly, once I've populated this, any good examples of how to turn it
into a bar chart? (the simple bar chart would be number of sales on the
y-axis, weeks before the event on the x-axis, however, what I'd then
like to do is split each bar into chunks for each venue's sales, if that
makes sense?)
This might give you an example of what you need:

http://matplotlib.sourceforge.net/examples/pylab_examples/bar_stacked.html

but you'd be better off asking on matplotlib-users.

David
Chris Withers
2011-08-20 23:52:01 UTC
Permalink
Post by David Warde-Farley
Post by Chris Withers
Secondly, once I've populated this, any good examples of how to turn it
into a bar chart? (the simple bar chart would be number of sales on the
y-axis, weeks before the event on the x-axis, however, what I'd then
like to do is split each bar into chunks for each venue's sales, if that
makes sense?)
http://matplotlib.sourceforge.net/examples/pylab_examples/bar_stacked.html
but you'd be better off asking on matplotlib-users.
Thanks, that was a good start.

One question: How can I automatically get a list of colours for each
bar? I don't know how many bars I'm going to have so I can't manually
pick them...

This feels like a common enough problem that I'm guessing there's a
solution somewhere in matplotlib?

cheers,

Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
Dav Clark
2011-08-09 20:46:35 UTC
Permalink
Post by Chris Withers
Hi All,
I'm a new user returning to SciPy after quite a long break, so, a few
- Are there any good books or other narrative docs that cover the bulk
of the core numpy stuff
- Ditto, but for visualisation, particularly with matplotlib or the
Enthought visualisation suites.
Well, this is probably more basic than you want, but O'Reilly's "Data Analysis with Open Source Tools" is certainly a nice low-level intro for a beginner:

http://oreilly.com/catalog/9780596802363

It's available on Safari Bookshelf, and also talks about using matplotlib (and R and GSL and ...). I'm unaware of any nice Chaco "narratives."
Post by Chris Withers
Now, first question: what's the best way to build this array given that
I may only see the arrival of a new venue a fair way through building
the data structure? How can I efficiently say "please add a new row to
my array", I don't know what the 4th dimension equivalent is ;-)
You might consider doing what matlab does under the hood and just double the array when you run out of space. You can also keep a view around that restricts to just the portion of the data that's "real."
Post by Chris Withers
Secondly, once I've populated this, any good examples of how to turn it
into a bar chart? (the simple bar chart would be number of sales on the
y-axis, weeks before the event on the x-axis, however, what I'd then
like to do is split each bar into chunks for each venue's sales, if that
makes sense?)
The book above would do a good job with this.

Cheers,
Dav
Chris Withers
2011-08-12 05:38:15 UTC
Permalink
Post by Dav Clark
http://oreilly.com/catalog/9780596802363
It's available on Safari Bookshelf, and also talks about using matplotlib (and R and GSL and ...). I'm unaware of any nice Chaco "narratives."
Thanks to you and everyone else for the great suggestions :-)
Post by Dav Clark
Post by Chris Withers
Now, first question: what's the best way to build this array given that
I may only see the arrival of a new venue a fair way through building
the data structure? How can I efficiently say "please add a new row to
my array", I don't know what the 4th dimension equivalent is ;-)
You might consider doing what matlab does under the hood and just double the array when you run out of space.
What's the best way to do this?

cheers,

Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
Jonathan Rocher
2011-08-12 07:00:41 UTC
Permalink
Dear Chris,

for documentation about the Enthought Tools Suite (open source, BSD-like
licence), let me point you to
http://code.enthought.com/
Specifically about 2D visualization, Chaco is good at building interactive
plotting tools efficiently even with large datasets. Its entire
documentation can be found at
http://github.enthought.com/chaco/
The documentation is not perfect but you can definitely find lots of
examples to follow in the
Tutorials<http://github.enthought.com/chaco/user_manual/tutorial.html>section
as well as in the
gallery <http://code.enthought.com/projects/chaco/gallery.php>.

Hope this helps.
Jonathan
Post by Dav Clark
Post by Dav Clark
Well, this is probably more basic than you want, but O'Reilly's "Data
Analysis with Open Source Tools" is certainly a nice low-level intro for a
Post by Dav Clark
http://oreilly.com/catalog/9780596802363
It's available on Safari Bookshelf, and also talks about using matplotlib
(and R and GSL and ...). I'm unaware of any nice Chaco "narratives."
Thanks to you and everyone else for the great suggestions :-)
Post by Dav Clark
Post by Chris Withers
Now, first question: what's the best way to build this array given that
I may only see the arrival of a new venue a fair way through building
the data structure? How can I efficiently say "please add a new row to
my array", I don't know what the 4th dimension equivalent is ;-)
You might consider doing what matlab does under the hood and just double
the array when you run out of space.
What's the best way to do this?
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
_______________________________________________
SciPy-User mailing list
http://mail.scipy.org/mailman/listinfo/scipy-user
--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
***@enthought.com
1-512-536-1057
http://www.enthought.com
Gökhan Sever
2011-08-10 17:48:30 UTC
Permalink
Post by Chris Withers
Hi All,
I'm a new user returning to SciPy after quite a long break, so, a few
- Are there any good books or other narrative docs that cover the bulk
of the core numpy stuff
- Ditto, but for visualisation, particularly with matplotlib or the
Enthought visualisation suites.
I'm particularly interested in step-by-step docs/books with lots of
examples, versus reference docs that basically need the user to know
what they're looking for in a chicken and egg fashion, which was my
previous experience of scipy docs...
Somewhat an advanced data analysis book, particularly if you are
interested in error analysis, and not so surprisingly powered by
Python:

A Student's Guide to Data and Error Analysis
[http://www.cambridge.org/gb/knowledge/isbn/item5731787/]
--
Gökhan
Paul Blelloch
2011-08-10 18:48:11 UTC
Permalink
I recently got Hans Petter Langtangen's "A Primer on Scientific Programming with Python." I thought that it was a good choice. It's more of a text book than a reference, but is well written. He has another book called "Python Scripting for Computational Science," which might also serve.

-----Original Message-----
From: scipy-user-***@scipy.org [mailto:scipy-user-***@scipy.org] On Behalf Of Gökhan Sever
Sent: Wednesday, August 10, 2011 10:49 AM
To: SciPy Users List
Subject: Re: [SciPy-User] getting started with arrays and matplotlib
Post by Chris Withers
Hi All,
I'm a new user returning to SciPy after quite a long break, so, a few
- Are there any good books or other narrative docs that cover the bulk
of the core numpy stuff
- Ditto, but for visualisation, particularly with matplotlib or the
Enthought visualisation suites.
I'm particularly interested in step-by-step docs/books with lots of
examples, versus reference docs that basically need the user to know
what they're looking for in a chicken and egg fashion, which was my
previous experience of scipy docs...
Somewhat an advanced data analysis book, particularly if you are
interested in error analysis, and not so surprisingly powered by
Python:

A Student's Guide to Data and Error Analysis
[http://www.cambridge.org/gb/knowledge/isbn/item5731787/]
--
Gökhan
martin smith
2011-08-10 19:59:23 UTC
Permalink
Post by Paul Blelloch
I recently got Hans Petter Langtangen's "A Primer on Scientific Programming with Python." I thought that it was a good choice. It's more of a text book than a reference, but is well written. He has another book called "Python Scripting for Computational Science," which might also serve.
I'd like to support the recommendation for Langtangen's book (I haven't
seen the second one). I think it's an excellent combination of advanced
script usage and scientific applications.

- martin smith
Loading...