Anonymous user
Matplotlib: Difference between revisions
→Project setup
imported>Jesstess No edit summary |
|||
(22 intermediate revisions by 10 users not shown) | |||
Line 1:
[[File:grid.png|right|300px]]
Very nice site!
Very nice site!
Very nice site!
== Project steps ==
Line 64 ⟶ 29:
<pre>pyplot.plot([0, 2, 4, 8, 16, 32], "o-")</pre>
and re-run the script. What changed?
</li>
<li>
Line 75 ⟶ 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 96 ⟶ 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 ===
Line 136 ⟶ 104:
<pre>pyplot.plot(my_data_1, "mo-", label="my data 1")
pyplot.plot(my_data_2, "bo-",
will plot <code>my_data_1</code> in magenta and <code>my_data_2</code> in blue on the same figure.
Supply labels for your plots, like above. Then use <code>pyplot.legend</code> to give your graph a legend. Just plain <code>pyplot.legend()</code> will work, but providing more options may give a better effect.
Your graph should look something like this:
Line 157 ⟶ 125:
</li>
<li>
Examples of legends: http://matplotlib.sourceforge.net/examples/pylab_examples/legend_auto.html
</li>
<li>
Line 166 ⟶ 134:
</li>
</ul>
==Bonus exercises==
Line 191 ⟶ 158:
===Congratulations!===
You've read, modified, and created scripts that plot and analyze data using matplotlib. Keep practicing!
[[File:Fireworks.png|150px]]
|