Skip to content

Commit

Permalink
remove <div> tags for fig width adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
bairdlangenbrunner committed Aug 2, 2018
1 parent 8646ba2 commit 8d2639c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions _site/collections/_matplotlib/pcolormesh-grid-fix.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ <h2 id="contourf-looks-fine">contourf looks fine…</h2>
<span class="n">cbar</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s">'elevation (m)'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
</code></pre></div></div>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/contourf_topo.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/contourf_topo.png" alt="" /></p>

<p>Notice the edges are a little rough looking, since <code class="highlighter-rouge">contourf</code> is interpolating up against NaN values that we placed into the data array where there was less than 10% land.</p>

Expand Down Expand Up @@ -290,11 +290,11 @@ <h2 id="but-pcolormesh-is-offset">…but pcolormesh is offset</h2>
<span class="n">cbar</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s">'elevation (m)'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
</code></pre></div></div>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong.png" alt="" /></p>

<p>I realize that this kind of thing isn’t <em>that</em> bad, especially if you’re looking at global plots where coastline details matter less. But I avoided <code class="highlighter-rouge">pcolormesh</code> for a long time because of this effect. When you zoom in, it looks even worse:</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong_zoom.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong_zoom.png" alt="" /></p>

<p>What’s going on can be found in the <a href="https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolor.html"><code class="highlighter-rouge">pcolor</code> documentation</a>: There’s actually an <em>interpolation</em> happening, where the function interpolates the original grid to its <strong>vertices</strong> and thereby shortens the latitude and longitude data by a row and column each. So the elevation values plotted above are correct; there’s no interpolation happening there (to my knowledge). It’s just that the latitude and longitude grids have been interpolated internally. This leads to the offset seen above.</p>

Expand Down Expand Up @@ -360,17 +360,17 @@ <h2 id="fix-it-by-interpolating-latitude-and-longitude-arrays-to-midpoints">Fix

<p>Now it’s looking good…</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct.png" alt="" /></p>

<p>…even when we zoom in:</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_zoom.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_zoom.png" alt="" /></p>

<p>The coarseness of the model grid is still going to look a <em>little</em> funny against coastlines, but that’s about as good as we can get at this resolution.</p>

<p>Even on a global grid that requires reprojection, we can be rest assured that the coastlines are lining up as well as they can:</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_homolosine.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_homolosine.png" alt="" /></p>


</div>
Expand Down
2 changes: 1 addition & 1 deletion _site/feed.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.7.3">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2018-08-02T08:10:51-07:00</updated><id>http://localhost:4000/</id><title type="html">Python for climate scientists</title><subtitle>Materials for Earth science data wrangling</subtitle><author><name>Baird</name></author></feed>
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.7.3">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2018-08-02T08:16:22-07:00</updated><id>http://localhost:4000/</id><title type="html">Python for climate scientists</title><subtitle>Materials for Earth science data wrangling</subtitle><author><name>Baird</name></author></feed>
12 changes: 6 additions & 6 deletions _site/matplotlib/pcolormesh-grid-fix.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ <h2 id="contourf-looks-fine">contourf looks fine…</h2>
<span class="n">cbar</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s">'elevation (m)'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
</code></pre></div></div>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/contourf_topo.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/contourf_topo.png" alt="" /></p>

<p>Notice the edges are a little rough looking, since <code class="highlighter-rouge">contourf</code> is interpolating up against NaN values that we placed into the data array where there was less than 10% land.</p>

Expand Down Expand Up @@ -289,11 +289,11 @@ <h2 id="but-pcolormesh-is-offset">…but pcolormesh is offset</h2>
<span class="n">cbar</span><span class="o">.</span><span class="n">set_label</span><span class="p">(</span><span class="s">'elevation (m)'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
</code></pre></div></div>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong.png" alt="" /></p>

<p>I realize that this kind of thing isn’t <em>that</em> bad, especially if you’re looking at global plots where coastline details matter less. But I avoided <code class="highlighter-rouge">pcolormesh</code> for a long time because of this effect. When you zoom in, it looks even worse:</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong_zoom.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong_zoom.png" alt="" /></p>

<p>What’s going on can be found in the <a href="https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolor.html"><code class="highlighter-rouge">pcolor</code> documentation</a>: There’s actually an <em>interpolation</em> happening, where the function interpolates the original grid to its <strong>vertices</strong> and thereby shortens the latitude and longitude data by a row and column each. So the elevation values plotted above are correct; there’s no interpolation happening there (to my knowledge). It’s just that the latitude and longitude grids have been interpolated internally. This leads to the offset seen above.</p>

Expand Down Expand Up @@ -359,17 +359,17 @@ <h2 id="fix-it-by-interpolating-latitude-and-longitude-arrays-to-midpoints">Fix

<p>Now it’s looking good…</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct.png" alt="" /></p>

<p>…even when we zoom in:</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_zoom.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_zoom.png" alt="" /></p>

<p>The coarseness of the model grid is still going to look a <em>little</em> funny against coastlines, but that’s about as good as we can get at this resolution.</p>

<p>Even on a global grid that requires reprojection, we can be rest assured that the coastlines are lining up as well as they can:</p>

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_homolosine.png)</div>
<p><img src="https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_homolosine.png" alt="" /></p>


</div>
Expand Down
12 changes: 6 additions & 6 deletions collections/_matplotlib/pcolormesh-grid-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cbar.ax.tick_params(labelsize=12)
cbar.set_label('elevation (m)', fontsize=12)
```

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/contourf_topo.png)</div>
![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/contourf_topo.png)


Notice the edges are a little rough looking, since ```contourf``` is interpolating up against NaN values that we placed into the data array where there was less than 10% land.
Expand Down Expand Up @@ -161,11 +161,11 @@ cbar.ax.tick_params(labelsize=12)
cbar.set_label('elevation (m)', fontsize=12)
```

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong.png)</div>
![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong.png)

I realize that this kind of thing isn't *that* bad, especially if you're looking at global plots where coastline details matter less. But I avoided ```pcolormesh``` for a long time because of this effect. When you zoom in, it looks even worse:

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong_zoom.png)</div>
![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_wrong_zoom.png)

What's going on can be found in the [```pcolor``` documentation][pcolor-site]: There's actually an *interpolation* happening, where the function interpolates the original grid to its **vertices** and thereby shortens the latitude and longitude data by a row and column each. So the elevation values plotted above are correct; there's no interpolation happening there (to my knowledge). It's just that the latitude and longitude grids have been interpolated internally. This leads to the offset seen above.

Expand Down Expand Up @@ -231,17 +231,17 @@ cbar.set_label('elevation (m)', fontsize=12)

Now it's looking good...

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct.png)</div>
![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct.png)

...even when we zoom in:

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_zoom.png)</div>
![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_zoom.png)

The coarseness of the model grid is still going to look a *little* funny against coastlines, but that's about as good as we can get at this resolution.

Even on a global grid that requires reprojection, we can be rest assured that the coastlines are lining up as well as they can:

<div style="width:100%">![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_homolosine.png)</div>
![](https://bairdlangenbrunner.github.io/python-for-climate-scientists/figures/pcolormesh/pcolormesh_correct_homolosine.png)

[pcolor-site]: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolor.html
[pcolormesh-site]: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pcolormesh.html
Expand Down

0 comments on commit 8d2639c

Please sign in to comment.