forked from swcarpentry/web-data-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-visualize.html
84 lines (83 loc) · 4.19 KB
/
04-visualize.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>Software Carpentry: Working With Data on the Web</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<link rel="alternate" type="application/rss+xml" title="Software Carpentry Blog" href="http://software-carpentry.org/feed.xml"/>
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner">
<a href="http://software-carpentry.org" title="Software Carpentry">
<img alt="Software Carpentry banner" src="img/software-carpentry-banner.png" />
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h1 class="title">Working With Data on the Web</h1>
<h2 class="subtitle">Visualization</h2>
<div id="learning-objectives" class="objectives panel panel-warning">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
</div>
<div class="panel-body">
<ul>
<li>Construct a simple visualization.</li>
</ul>
</div>
</div>
<p>We now have all the tools we need to visualize the temperature differences between countries:</p>
<pre class="sourceCode python"><code class="sourceCode python"><span class="ch">from</span> matplotlib <span class="ch">import</span> pyplot <span class="ch">as</span> plt
australia = get_annual_mean_temp_by_country(<span class="st">'AUS'</span>)
canada = get_annual_mean_temp_by_country(<span class="st">'CAN'</span>)
diff = diff_records(australia, canada)
plt.plot(diff)
plt.show()</code></pre>
<div class="figure">
<img src="fig/plot-01.png" alt="First Plot" /><p class="caption">First Plot</p>
</div>
<p>That’s not what we want: the library has interpreted our list of pairs as two corresponding curves rather than as the (x,y) coordinates for one curve. Let’s convert our list of (year, difference) pairs into a NumPy array:</p>
<pre class="sourceCode python"><code class="sourceCode python"><span class="ch">import</span> numpy <span class="ch">as</span> np
d = np.array(diff)</code></pre>
<p>and then plot the first column against the second:</p>
<pre class="sourceCode python"><code class="sourceCode python">plt.plot(d[:, <span class="dv">0</span>], d[:, <span class="dv">1</span>])
plt.show()</code></pre>
<div class="figure">
<img src="fig/plot-02.png" alt="Second Plot" /><p class="caption">Second Plot</p>
</div>
<p>It looks like the difference is slowly decreasing, but the signal is very noisy. At this point, if we wanted a real answer, it would be time to break out a curve-fitting library.</p>
<div id="changing-visualizations" class="challenge panel panel-success">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pencil"></span>Changing Visualizations</h2>
</div>
<div class="panel-body">
<p>Modify the plotting commands so that the Y-axis scale runs from 0 to 32. Do you think this gives you a more accurate or less accurate view of this data?</p>
</div>
</div>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="http://software-carpentry.org">Software Carpentry</a>
<a class="label swc-blue-bg" href="https://github.com/swcarpentry/lesson-template">Source</a>
<a class="label swc-blue-bg" href="mailto:[email protected]">Contact</a>
<a class="label swc-blue-bg" href="LICENSE.html">License</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://software-carpentry.org/v5/js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
</body>
</html>