Editing Matplotlib

From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
[[File:Matplotlib-hist2d.png|right|500px]]
[[File:Matplotlib-hist2d.png|right|500px]]
__NOTOC__
__NOTOC__
== Getting Started ==
== Visualizing data with Matplotlib and Wiki-bios ==
Download the CDSW Matplotlib code from [https://github.com/makoshark/matplotlib-cdsw/archive/master.zip here] and unzip it on your machine.
 
We will also need the data file that is [http://communitydata.cc/~mako/hp_wiki.tsv here]
 
== Visualizing data with Matplotlib ==


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.
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 start with the data-set created [[Community_Data_Science_Workshops_(Fall_2015)/Day_3_Lecture|this morning]] containing information about edits to the Harry Potter Wikipedia article.  
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.


We will then proceed to visualize different aspects of data from the [[Community_Data_Science_Workshops_(Fall_2015)/Day_2_Projects/Socrata|Socrata web API]].
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.
 
 
=== Inspiration ===
 
* [https://flowingdata.com/ Flowing Data]
* [http://www-01.ibm.com/software/analytics/many-eyes/ Many Eyes]
* [http://www.edwardtufte.com/tufte/ Edward Tufte]
* [http://www.visualizing.org/ visualizing.org]
* [http://idl.cs.washington.edu/ UW Interactive Data Lab]


=== Goals ===
=== Goals ===
Line 33: Line 19:
* Exercise your creativity by making your own visualization
* Exercise your creativity by making your own visualization


# First plot: <tt>001-hello-plot.py</tt>
=== Download and test the Matplotlib-with-Wiki-bios project ===
# Subplots: <tt>002-subplots.py</tt>
 
# Let's do something more interesting: <tt>003-plot-timeseries.py</tt>
(Estimated time: 10 minutes)
# Visit the [http://matplotlib.org/gallery.html Matplotlib gallery].
 
# Make another kind of plot: <tt>004-plot-histogram.py</tt>
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.
# Dive deeper into web APIs: <tt>005-traffic-timeseries.py</tt>
 
# Play around with any/all the data you've seen! You can find some more examples in the <tt>wikibios</tt> folder.
Bundle with code for all platforms: http://mako.cc/teaching/2014/cdsw-autumn/wikibios.zip
 
=== References ===
=== References ===


Line 46: Line 32:
* [http://matplotlib.org/examples/index.html matplotlib Examples] (many, with source)
* [http://matplotlib.org/examples/index.html matplotlib Examples] (many, with source)
* Other plotting resources
* 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://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://ggplot.yhathq.com/ ggplot]: port of the R language's ggplot2 library to python
Line 61: Line 48:


[[File:Wikipedia.png|right|250px]]
[[File:Wikipedia.png|right|250px]]
[[Category:CDSW]]
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see CommunityData:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)