Skip to content

Commit d5cf5bb

Browse files
authored
Merge pull request #3 from stefmolin/reproducible-svg
Consistent SVG outputs across runs
2 parents 16322dd + 7e609d6 commit d5cf5bb

14 files changed

+20033
-19533
lines changed

notebooks/2-data_wrangling.ipynb

Lines changed: 839 additions & 824 deletions
Large diffs are not rendered by default.

notebooks/3-data_visualization.ipynb

Lines changed: 3179 additions & 3030 deletions
Large diffs are not rendered by default.

notebooks/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Utility function for the workshop."""
2+
3+
import datetime as dt
4+
5+
6+
def mpl_svg_config(hashsalt):
7+
"""Help configure the SVG backend for Matplotlib and make it reproducible."""
8+
from matplotlib import rc
9+
rc('svg', hashsalt=hashsalt)
10+
11+
return {
12+
'metadata': {
13+
'Date': f'(c) 2021-{dt.date.today().year} Stefanie Molin'
14+
}
15+
}

slides/2-data_wrangling.ipynb

Lines changed: 839 additions & 824 deletions
Large diffs are not rendered by default.

slides/3-data_visualization.ipynb

Lines changed: 4199 additions & 4065 deletions
Large diffs are not rendered by default.

slides/html/0-introduction.slides.html

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
.highlight .m { color: var(--jp-mirror-editor-number-color) } /* Literal.Number */
5252
.highlight .s { color: var(--jp-mirror-editor-string-color) } /* Literal.String */
5353
.highlight .ow { color: var(--jp-mirror-editor-operator-color); font-weight: bold } /* Operator.Word */
54+
.highlight .pm { color: var(--jp-mirror-editor-punctuation-color) } /* Punctuation.Marker */
5455
.highlight .w { color: var(--jp-mirror-editor-variable-color) } /* Text.Whitespace */
5556
.highlight .mb { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Bin */
5657
.highlight .mf { color: var(--jp-mirror-editor-number-color) } /* Literal.Number.Float */
@@ -14484,6 +14485,12 @@
1448414485
.jp-RenderedHTMLCommon.jp-RenderedHTML.jp-OutputArea-output.jp-OutputArea-executeResult {
1448514486
padding-right: 5px !important; /* padding after lead-in text */
1448614487
}
14488+
.jp-RenderedSVG > svg, .jp-OutputArea-output > svg { /* scale SVG plots */
14489+
width: 75%;
14490+
}
14491+
.jp-Collapser { /* hide that blue collapse button on the side of cells that does nothing */
14492+
display: none;
14493+
}
1448714494
.CodeMirror pre {
1448814495
padding: 0.4em !important;
1448914496
overflow-x: scroll !important; /* allow scrolling to see full code block */
@@ -14495,8 +14502,8 @@
1449514502
right: 5px !important;
1449614503
bottom: 5px !important;
1449714504
}
14498-
.jp-RenderedSVG > svg, .jp-OutputArea-output > svg { /* scale SVG plots */
14499-
width: 75%;
14505+
.slides { /* pull slides to left */
14506+
margin-left: -20px !important;
1450014507
}
1450114508
:root {
1450214509
--jp-ui-font-size1: 11.5px; /* size of tables in outputs */
@@ -14619,17 +14626,14 @@
1461914626

1462014627
/* Scrollbars */
1462114628

14622-
::-webkit-scrollbar
14623-
{
14629+
::-webkit-scrollbar {
1462414630
width: 6px;
1462514631
height: 6px;
1462614632
}
14627-
::-webkit-scrollbar *
14628-
{
14629-
background:transparent;
14633+
::-webkit-scrollbar * {
14634+
background: transparent;
1463014635
}
14631-
::-webkit-scrollbar-thumb
14632-
{
14636+
::-webkit-scrollbar-thumb {
1463314637
background: #727272 !important;
1463414638
}
1463514639
</style>
@@ -14656,12 +14660,12 @@
1465614660
},
1465714661
displayAlign: 'center',
1465814662
CommonHTML: {
14659-
linebreaks: {
14660-
automatic: true
14663+
linebreaks: {
14664+
automatic: true
1466114665
}
1466214666
}
1466314667
});
14664-
14668+
1466514669
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
1466614670
}
1466714671
}
@@ -14683,7 +14687,7 @@
1468314687
</a>
1468414688
</div>
1468514689
</div>
14686-
<div class="slides"><section><section>
14690+
<div class="slides"><section ><section >
1468714691
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell">
1468814692
<div class="jp-Cell-inputWrapper">
1468914693
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
@@ -14694,7 +14698,7 @@ <h1 id="Introduction-to-Data-Analysis-Using-Pandas">Introduction to Data Analysi
1469414698
</div>
1469514699
</div>
1469614700
</div>
14697-
</div></section><section>
14701+
</div></section><section >
1469814702
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell">
1469914703
<div class="jp-Cell-inputWrapper">
1470014704
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
@@ -14712,7 +14716,7 @@ <h2 id="Bio">Bio<a class="anchor-link" href="#Bio">&#182;</a></h2><ul>
1471214716
</div>
1471314717
</div>
1471414718
</div>
14715-
</div></section></section><section><section>
14719+
</div></section></section><section ><section >
1471614720
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell">
1471714721
<div class="jp-Cell-inputWrapper">
1471814722
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
@@ -14724,7 +14728,7 @@ <h3 id="Prerequisites">Prerequisites<a class="anchor-link" href="#Prerequisites"
1472414728
</div>
1472514729
</div>
1472614730
</div>
14727-
</div></section></section><section><section>
14731+
</div></section></section><section ><section >
1472814732
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell">
1472914733
<div class="jp-Cell-inputWrapper">
1473014734
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
@@ -14741,15 +14745,15 @@ <h3 id="Session-Outline">Session Outline<a class="anchor-link" href="#Session-Ou
1474114745
</div>
1474214746
</div>
1474314747
</div>
14744-
</div></section></section><section><section>
14748+
</div></section></section><section ><section >
1474514749
<div class="jp-Cell jp-MarkdownCell jp-Notebook-cell">
1474614750
<div class="jp-Cell-inputWrapper">
1474714751
<div class="jp-Collapser jp-InputCollapser jp-Cell-inputCollapser">
1474814752
</div>
1474914753
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
1475014754
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput celltag_id_follow-along" data-mime-type="text/markdown">
1475114755
<h2 id="Let's-get-started">Let's get started<a class="anchor-link" href="#Let's-get-started">&#182;</a></h2><p><em>Be sure to follow along in the <a href="https://github.com/stefmolin/pandas-workshop/tree/main/notebooks">notebooks</a>.</em></p>
14752-
<p><img width="30%" src="https://www.pngkey.com/png/detail/42-428839_silhouette-face-bamboo-cartoon-wild-bear-cute-panda.png" alt="Silhouette, Face, Bamboo, Cartoon, Wild, Bear, Cute - Panda Black And White@pngkey.com" style="min-width: 300px"></p>
14756+
<img width="30%" src="https://www.pngkey.com/png/detail/42-428839_silhouette-face-bamboo-cartoon-wild-bear-cute-panda.png" alt="Silhouette, Face, Bamboo, Cartoon, Wild, Bear, Cute - Panda Black And White@pngkey.com" style="min-width: 300px">
1475314757

1475414758
</div>
1475514759
</div>
@@ -14821,7 +14825,8 @@ <h2 id="Let's-get-started">Let's get started<a class="anchor-link" href="#Let's-
1482114825
if (!isNaN(input)) {
1482214826
const requestedSlideNumber = Math.max(Math.min(input, slides.length) - 1, 0);
1482314827
const slideIndices = Reveal.getIndices(slides[requestedSlideNumber]);
14824-
Reveal.slide(slideIndices.h, slideIndices.v, 100); // set fragment to large number to ensure the full slide is displayed
14828+
// set fragment to large number (100) to ensure the full slide is displayed
14829+
Reveal.slide(slideIndices.h, slideIndices.v, 100);
1482514830
}
1482614831
else if (typeof input === "string" || input instanceof String) {
1482714832
const slideName = input.replaceAll(' ', '-');
@@ -14903,6 +14908,26 @@ <h2 id="Let's-get-started">Let's get started<a class="anchor-link" href="#Let's-
1490314908
() => { window.location = `#/${id}`; }
1490414909
);
1490514910
}
14911+
14912+
// fix any collisions in the clip-path introduced from reproducible SVG plots
14913+
// that cause plot components not to render (clipPath objects with duplicate IDs)
14914+
const clipPathIds = {};
14915+
$('clipPath').each((index, element) => {
14916+
const oldId = $(element).attr('id');
14917+
if (oldId in clipPathIds) {
14918+
// change this id and grab the parent SVG
14919+
// and then for all the elements with clip-path switch the id
14920+
const newId = `${oldId}${clipPathIds[oldId]}`;
14921+
$(element).attr('id', newId);
14922+
$(element).closest('svg').find('[clip-path]').each((index, item) => {
14923+
if ($(item).attr('clip-path') === `url(#${oldId})`) {
14924+
$(item).attr('clip-path', `url(#${newId})`);
14925+
}
14926+
});
14927+
clipPathIds[oldId] += 1;
14928+
}
14929+
else clipPathIds[oldId] = 1;
14930+
});
1490614931
}
1490714932
);
1490814933
</script>

0 commit comments

Comments
 (0)