Matplotlib: Difference between revisions

2,453 bytes removed ,  7 years ago
imported>Jesstess
 
(13 intermediate revisions by 9 users not shown)
Line 1:
[[File:grid.png|right|300px]]
 
Very nice site!
== Project ==
 
Very nice site!
Learn how to plot data with the matplotlib plotting library. Ditch Excel forever!
 
Very nice site!
== Goals ==
 
* practice reading data from a file
* practice using the matplotlib Python plotting library to analyze data and generate graphs
 
 
== Project setup ==
 
=== 1. Install the project dependencies ===
 
Please follow the official matplotlib installation instructions at http://matplotlib.sourceforge.net/users/installing.html
 
The dependencies vary across operating systems. http://matplotlib.sourceforge.net/users/installing.html#build-requirements summarizes what you'll need for your operating system. We also give specific recommendations for each platform below.
 
Installing matplotlib and its dependencies is somewhat involved; please ask for help if you get stuck or don't know where to start!
 
==== Windows users only ====
 
# Download and install numpy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
# Download and install matplotlib from http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib
 
==== Mac OS X users only ====
 
If you do not already have a C compiler installed, you'll need to install one before you install matplotlib. You have several options depending on your situation:
# Download and install Xcode (1.5 GB) from https://developer.apple.com/xcode/
# Download and install Command Line Tools for Xcode (175 MB) from https://developer.apple.com/downloads/index.action. This requires an Apple Developer account (free, but you have to sign up).
# Download and install kennethreitz's gcc installer (requires OS X 10.6 or 10.7) from https://github.com/kennethreitz/osx-gcc-installer/
 
Please wave over a staff member and we'll help you pick which option is best for you computer.
 
<!--
# Download and install numpy from http://sourceforge.net/projects/numpy/
# Read http://matplotlib.sourceforge.net/faq/installing_faq.html#install-osx-binaries and then download and install matplotlib from http://sourceforge.net/projects/matplotlib/files/matplotlib/
-->
 
 
==== Linux users only ====
 
# Install the <code>python-numpy</code> package through your package manager
# Install the <code>python-matplotlib</code> package through your package manager
 
=== 2. Download and un-archive the Matplotlib project skeleton code ===
 
* http://web.mit.edu/jesstess/www/IntermediatePythonWorkshop/Matplotlib.zip
 
Un-archiving will produce a <code>Matplotlib</code> folder containing several Python and text files.
 
=== 3. Test your setup ===
 
Run the <code>basic_plot.py</code> script in your <code>Matplotlib</code> directory. A window with a graph should pop up.
 
== Project steps ==
Line 78 ⟶ 29:
 
<pre>pyplot.plot([0, 2, 4, 8, 16, 32], "o-")</pre>
 
and re-run the script. What changed?
</li>
<li>
Line 89 ⟶ 42:
y_values = [0, 2, 4, 8, 16, 32]
pyplot.plot(x_values, y_values, "o-")</pre>
 
and re-run the script. What changed?
 
Note how matplotlib automatically resizes the graph to fit all of the points in the figure for you.
Line 110 ⟶ 65:
* What does matplotlib pick as the x values if you don't supply them yourself?
* What options would you pass to <code>pyplot.plot</code> to generate a plot with red triangles and dotted lines?
 
 
=== 2. Plotting the world population over time ===
Anonymous user