Matplotlib: Difference between revisions

From CommunityData
(Created this page from the Spring 2014 version, changed the link to match.)
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
== Visualizing data with Matplotlib and Wiki-bios ==
== Visualizing data with Matplotlib and Wiki-bios ==


In this project, we will explore how to produce clear, informative charts, graphs, and plots with [http://matplotlib.org/ Matplotlib], the most popular toolkit for scientific data visualization in Python.
In this session, we will explore how to produce clear, informative charts, graphs, and plots with [http://matplotlib.org/ Matplotlib], the most popular toolkit for scientific data visualization in Python.


We'll be focusing on a dataset drawn from Wikipedia and [http://dbpedia.org DBpedia], containing the names, birth dates, genders, article creation dates, and number of edits, of over 180,000 Wikipedia biography articles.
We'll be focusing on a dataset drawn from Wikipedia and , containing the names, birth dates, genders, article creation dates, and number of edits, of over 180,000 Wikipedia biography articles.
 
The dataset used here has been drawn from several sources. The list of biographies and the gender of the biography subjects comes from a datbase called [http://dbpedia.org DBpedia] that is a structured database built from Wikipedia. If determines if articles are biographies from the Wikipedia category system and it determines if the subjects are male or female primarily by looking at whether subject is referred to as ''he'' or ''she'' in the article. Birthdates for people are extracted from the data recorded in Wikipedia in the "infobox" sidebars common to many pages. Data on how people edit Wikipedia is merged onto this dataset from a separate collection of metadata of Wikipedia editing very similar to the one we built for Harry Potter articles the morning.


=== Goals ===
=== Goals ===
Line 23: Line 25:
After installing matplotlib, and downloading and unpacking the Wikibios bundle, move into that directory with '''cd'''.  You can test your installation by running '''python histograms.py'''.  If matplotlib is install correcting, a chart file named '''histograms.pdf''' will appear in the current directory.
After installing matplotlib, and downloading and unpacking the Wikibios bundle, move into that directory with '''cd'''.  You can test your installation by running '''python histograms.py'''.  If matplotlib is install correcting, a chart file named '''histograms.pdf''' will appear in the current directory.


[http://mako.cc/teaching/2014/cdsw-autumn/wikibios.zip Wikibios bundle for all platforms]
Bundle with code for all platforms: http://mako.cc/teaching/2014/cdsw-autumn/wikibios.zip
 
=== References ===
 
* [http://matplotlib.org/api/pyplot_summary.html matplotlib API reference]
* [http://matplotlib.org/examples/index.html matplotlib Examples] (many, with source)
* Other plotting resources
** [http://blog.olgabotvinnik.com/prettyplotlib/ prettyplotlib]: hip-aesthetic matplotlib plots
** [http://web.stanford.edu/~mwaskom/software/seaborn/ Seaborn]: fancy matplotlib-based visualizations
** [http://ggplot.yhathq.com/ ggplot]: port of the R language's ggplot2 library to python
** [http://d3js.org/ D3.js]: interactive data visualization for the browser (javascript)


=== Example topics to cover in Lecture ===
=== Example topics to cover in Lecture ===

Revision as of 04:43, 4 May 2015

Matplotlib-hist2d.png

Visualizing data with Matplotlib and Wiki-bios

In this session, we will explore how to produce clear, informative charts, graphs, and plots with Matplotlib, the most popular toolkit for scientific data visualization in Python.

We'll be focusing on a dataset drawn from Wikipedia and , containing the names, birth dates, genders, article creation dates, and number of edits, of over 180,000 Wikipedia biography articles.

The dataset used here has been drawn from several sources. The list of biographies and the gender of the biography subjects comes from a datbase called DBpedia that is a structured database built from Wikipedia. If determines if articles are biographies from the Wikipedia category system and it determines if the subjects are male or female primarily by looking at whether subject is referred to as he or she in the article. Birthdates for people are extracted from the data recorded in Wikipedia in the "infobox" sidebars common to many pages. Data on how people edit Wikipedia is merged onto this dataset from a separate collection of metadata of Wikipedia editing very similar to the one we built for Harry Potter articles the morning.

Goals

  • Get set up to make graphs with Matplotlib
  • Learn the basics of the Matplotlib API and workflow
  • Practice reading the Matplotlib documentation
  • Build a plotting program step by step
  • Learn simple ways to distill the essence of a large data set
  • Explore the art of visualizing data
  • Exercise your creativity by making your own visualization

Download and test the Matplotlib-with-Wiki-bios project

(Estimated time: 10 minutes)

After installing matplotlib, and downloading and unpacking the Wikibios bundle, move into that directory with cd. You can test your installation by running python histograms.py. If matplotlib is install correcting, a chart file named histograms.pdf will appear in the current directory.

Bundle with code for all platforms: http://mako.cc/teaching/2014/cdsw-autumn/wikibios.zip

References

Example topics to cover in Lecture

  • line charts
  • histograms
  • binning
  • scatter plots
  • heat maps
  • axis labeling
  • legends
Wikipedia.png