Matplotlib: Difference between revisions

Content added Content deleted
imported>Jesstess
imported>Jesstess
Line 76: Line 76:
== Project steps ==
== Project steps ==


=== Create a basic plot ===
=== 1. Create a basic plot ===


<ol>
<ol>
Line 104: Line 104:
to
to


<pre>x_values = [3, 4, 7, 20, 22, 25]
<pre>x_values = [0, 4, 7, 20, 22, 25]
y_values = [0, 2, 4, 8, 16, 32]
y_values = [0, 2, 4, 8, 16, 32]
pyplot.plot(x_values, y_values, "o-")</pre>
pyplot.plot(x_values, y_values, "o-")</pre>


Note how matplotlib automatically resizes the graph to fit all of the points in the figure for you.
Note how matplotlib automatically resizes the graph to fit all of the points in the figure for you.
</li>
<li>
Read about how to generate random integers on http://docs.python.org/library/random.html#random.randint.

Then, instead of hard-coding x values and y values in <code>basic_plot.py</code>, generate a list of random y values.

An example plot using random y values might look like this:

[File:Basic_plot.png|300px]
</li>
</li>
</ol>
</ol>
Line 121: Line 130:




=== Plotting the world population over time ===
=== 2. Plotting the world population over time ===


<ol>
<ol>