Matplotlib: Difference between revisions

imported>Jesstess
No edit summary
imported>Jesstess
</ol>
 
<b>WordWorld population resources</b>:
<ul>
<li>
 
 
=== 3. MakePlotting databaselife queriesexpectancy fromover Pythontime ===
 
In a new file, write code to plot the data in <code>life_expectancies_usa.txt</code>. The format in this file is <year>,<male life expectancy>,<female life expectancy>.
Examine the code in <code>jeopardy_categories.py</code>. To make a database query from Python, you need to:
# Import a Python library for making database connections
# Establish a connection to the desired database
# Get a cursor from the database for making queries
# Execute the database query using the standard SQL syntax
# Retrieve the list of results from the database cursor
# Do something useful with the results, like print them
# Close the database connection
 
You can call <code>pyplot.plot</code> multiple times to draw multiple lines on the same figure. For example:
Match up each of these steps with lines of code in the file.
 
<pre>pyplot.plot(my_data_1, "mo-", label="my data 1")
pyplot.plot(my_data_2, "bo-", "label="my data 2")</pre>
 
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.
 
Your graph should look something like this:
 
[[File:Life_expectancies.png|300px]]
 
To save your graph to a file instead of or in addition to displaying it, call <code>pyplot.savefig</code>.
 
<b>Life expectancy resources</b>:
<ul>
<li>
File input and output: http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files.
</li>
<li>
Splitting sprints into parts based on a delimiter: http://www.hacksparrow.com/python-split-string-method-and-examples.html
</li>
<li>
Examples of legends:
</li>
<li>
Ways to configure your legend: http://matplotlib.sourceforge.net/api/legend_api.html
</li>
<li>
Saving your graph to a file: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.savefig
</li>
</ul>
 
=== 4. Tweak the existing Jeopardy scripts ===
Anonymous user