Skip to content

Commit d248214

Browse files
committed
Examples; generating examples; cross-machine gold tests are too fragile
1 parent 73b883c commit d248214

File tree

4 files changed

+294
-4
lines changed

4 files changed

+294
-4
lines changed

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,122 @@ Once you have the prerequisites you can install using the standard incantation
3737
```bash
3838
cabal install matplotlib
3939
```
40+
41+
### Examples
42+
43+
Click on any of the examples below to go to the corresponding test that
44+
generates it. Depending on your matplotlib version default colors might be
45+
different.
46+
47+
[![quadratic][img_quadratic]][url_quadratic]
48+
[![labelled-histogram][img_labelled-histogram]][url_labelled-histogram]
49+
[![projections][img_projections]][url_projections]
50+
[![histogram][img_histogram]][url_histogram]
51+
[![pcolorlog][img_pcolorlog]][url_pcolorlog]
52+
[![scatter][img_scatter]][url_scatter]
53+
[![streamplot][img_streamplot]][url_streamplot]
54+
[![hist2DLog][img_hist2DLog]][url_hist2DLog]
55+
[![stacked][img_stacked]][url_stacked]
56+
[![legend][img_legend]][url_legend]
57+
[![errorbar][img_errorbar]][url_errorbar]
58+
[![griddata][img_griddata]][url_griddata]
59+
[![line-options][img_line-options]][url_line-options]
60+
[![quiver-fancy][img_quiver-fancy]][url_quiver-fancy]
61+
[![annotation][img_annotation]][url_annotation]
62+
[![integral][img_integral]][url_integral]
63+
[![contour][img_contour]][url_contour]
64+
[![boxplot][img_boxplot]][url_boxplot]
65+
[![show-matrix][img_show-matrix]][url_show-matrix]
66+
[![scatterhist][img_scatterhist]][url_scatterhist]
67+
[![hinton][img_hinton]][url_hinton]
68+
[![density][img_density]][url_density]
69+
[![violinplot][img_violinplot]][url_violinplot]
70+
[![histMulti][img_histMulti]][url_histMulti]
71+
[![spines][img_spines]][url_spines]
72+
[![corr][img_corr]][url_corr]
73+
[![cumulative][img_cumulative]][url_cumulative]
74+
[![polar][img_polar]][url_polar]
75+
[![hists][img_hists]][url_hists]
76+
[![tex][img_tex]][url_tex]
77+
[![eventplot][img_eventplot]][url_eventplot]
78+
[![line-function][img_line-function]][url_line-function]
79+
[![density-bandwidth][img_density-bandwidth]][url_density-bandwidth]
80+
[![bivariateNormal][img_bivariateNormal]][url_bivariateNormal]
81+
[![quiver][img_quiver]][url_quiver]
82+
[![pie][img_pie]][url_pie]
83+
[![images][img_images]][url_images]
84+
85+
[img_pcolorlog]: https://i.imgur.com/O8hU7Rl.png "pcolorlog"
86+
[url_pcolorlog]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L495
87+
[img_griddata]: https://i.imgur.com/Lh2xOPf.png "griddata"
88+
[url_griddata]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L602
89+
[img_streamplot]: https://i.imgur.com/AveIggT.png "streamplot"
90+
[url_streamplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L582
91+
[img_hist2DLog]: https://i.imgur.com/PnPyJzO.png "hist2DLog"
92+
[url_hist2DLog]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L275
93+
[img_cumulative]: https://i.imgur.com/W9JinZC.png "cumulative"
94+
[url_cumulative]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L217
95+
[img_eventplot]: https://i.imgur.com/2chP6qg.png "eventplot"
96+
[url_eventplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L280
97+
[img_quiver]: https://i.imgur.com/7G7r9gu.png "quiver"
98+
[url_quiver]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L423
99+
[img_labelled-histogram]: https://i.imgur.com/cOCIlpy.png "labelled-histogram"
100+
[url_labelled-histogram]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L226
101+
[img_line-options]: https://i.imgur.com/0Jr83hl.png "line-options"
102+
[url_line-options]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L249
103+
[img_violinplot]: https://i.imgur.com/MaWL0BD.png "violinplot"
104+
[url_violinplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L298
105+
[img_density]: https://i.imgur.com/v7GoIno.png "density"
106+
[url_density]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L241
107+
[img_tex]: https://i.imgur.com/liZci2C.png "tex"
108+
[url_tex]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L259
109+
[img_scatterhist]: https://i.imgur.com/DG3obq8.png "scatterhist"
110+
[url_scatterhist]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L305
111+
[img_boxplot]: https://i.imgur.com/aaoMEql.png "boxplot"
112+
[url_boxplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L292
113+
[img_histogram]: https://i.imgur.com/yO6dxEO.png "histogram"
114+
[url_histogram]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L214
115+
[img_images]: https://i.imgur.com/3ZqQDxR.png "images"
116+
[url_images]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L482
117+
[img_polar]: https://i.imgur.com/BTXgvqa.png "polar"
118+
[url_polar]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L450
119+
[img_histMulti]: https://i.imgur.com/hO2CFGQ.png "histMulti"
120+
[url_histMulti]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L334
121+
[img_annotation]: https://i.imgur.com/cPSB8BX.png "annotation"
122+
[url_annotation]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L539
123+
[img_corr]: https://i.imgur.com/fh4Bv2X.png "corr"
124+
[url_corr]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L254
125+
[img_scatter]: https://i.imgur.com/qg7W3oc.png "scatter"
126+
[url_scatter]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L219
127+
[img_hinton]: https://i.imgur.com/RPkTFIJ.png "hinton"
128+
[url_hinton]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L380
129+
[img_quiver-fancy]: https://i.imgur.com/VQ5RrfJ.png "quiver-fancy"
130+
[url_quiver-fancy]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L434
131+
[img_quadratic]: https://i.imgur.com/fs96snF.png "quadratic"
132+
[url_quadratic]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L245
133+
[img_line-function]: https://i.imgur.com/5REiBVO.png "line-function"
134+
[url_line-function]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L243
135+
[img_integral]: https://i.imgur.com/OxGr14f.png "integral"
136+
[url_integral]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L396
137+
[img_contour]: https://i.imgur.com/kMxGGot.png "contour"
138+
[url_contour]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L224
139+
[img_projections]: https://i.imgur.com/laubT7H.png "projections"
140+
[url_projections]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L247
141+
[img_legend]: https://i.imgur.com/EmpXjUY.png "legend"
142+
[url_legend]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L270
143+
[img_spines]: https://i.imgur.com/fc9xwh5.png "spines"
144+
[url_spines]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L352
145+
[img_density-bandwidth]: https://i.imgur.com/e48WAPS.png "density-bandwidth"
146+
[url_density-bandwidth]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L238
147+
[img_bivariateNormal]: https://i.imgur.com/ngX1N2R.png "bivariateNormal"
148+
[url_bivariateNormal]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L465
149+
[img_pie]: https://i.imgur.com/DSRqr14.png "pie"
150+
[url_pie]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L516
151+
[img_show-matrix]: https://i.imgur.com/bd6x6Es.png "show-matrix"
152+
[url_show-matrix]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L267
153+
[img_hists]: https://i.imgur.com/hJaxZJt.png "hists"
154+
[url_hists]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L371
155+
[img_errorbar]: https://i.imgur.com/ooTcL40.png "errorbar"
156+
[url_errorbar]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L287
157+
[img_stacked]: https://i.imgur.com/TIqlAtR.png "stacked"
158+
[url_stacked]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L523

geneate-table.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/python3
2+
"""Upload data to imgur if it's changed.
3+
4+
Usage:
5+
generate-table.py
6+
"""
7+
from docopt import docopt
8+
from collections import defaultdict
9+
import os
10+
import json
11+
import subprocess
12+
13+
def gen(name, md5):
14+
subprocess.check_output(["convert", name, "-resize", "x200", "-unsharp", "0x1", "/tmp/a.png"])
15+
r = subprocess.check_output(["./imgur.sh", "/tmp/a.png"]).strip().split()
16+
return {'md5': md5, 'link': r[0].decode("utf-8"), 'deleteLink': r[3].decode("utf-8")}
17+
18+
def doit():
19+
data = json.loads(open('uploaded-figures.json').read())
20+
for img in os.listdir("imgs"):
21+
img = 'imgs/' +img
22+
md5 = subprocess.check_output(["/usr/bin/md5sum", img]).strip().split()[0].decode("utf-8")
23+
if img in data and data[img]['md5'] == md5:
24+
pass
25+
else:
26+
data[img] = gen(img, md5)
27+
print(data[img])
28+
json.dump(data, open('uploaded-figures.json', 'w'))
29+
30+
def links():
31+
data = json.loads(open('uploaded-figures.json').read())
32+
for k, v in data.items():
33+
label = os.path.splitext(os.path.basename(k))[0]
34+
print('[img_%s]: %s "%s"' % (label, v['link'], label))
35+
fnName = subprocess.check_output(["/bin/grep", "-n", '"' + label + '"', "test/Spec.hs"]).split()[4].decode("utf-8")
36+
line = subprocess.check_output(["/bin/grep", "-ne", "^" + fnName + ' ', "test/Spec.hs"]).decode("utf-8").split(':')[0]
37+
print("[url_%s]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L%s" % (label, line))
38+
for k, v in data.items():
39+
label = os.path.splitext(os.path.basename(k))[0]
40+
print("[![%s][img_%s]][url_%s]" % (label, label, label))
41+
# "| %s | %s | %s |"
42+
# | col 2 is | centered | $12 |
43+
# | zebra stripes | are neat | $1 |
44+
45+
# [You can use numbers for reference-style link definitions][1]
46+
# ![alt text][logo]
47+
# [![alt text][logo]][1]
48+
# '[1]: http://slashdot.org'
49+
# '[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"'
50+
51+
if __name__ == '__main__':
52+
arguments = docopt(__doc__, version='0.1')
53+
doit()
54+
links()

imgur.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
3+
# Imgur script by Bart Nagel <bart@tremby.net>
4+
# Improvements by Tino Sino <robottinosino@gmail.com>
5+
# Version 6 or more
6+
# I release this into the public domain. Do with it what you will.
7+
# The latest version can be found at https://github.com/tremby/imgur.sh
8+
9+
# API Key provided by Bart;
10+
# replace with your own or specify yours as IMGUR_CLIENT_ID envionment variable
11+
# to avoid limits
12+
default_client_id=c9a6efb3d7932fd
13+
client_id="${IMGUR_CLIENT_ID:=$default_client_id}"
14+
15+
# Function to output usage instructions
16+
function usage {
17+
echo "Usage: $(basename $0) [<filename|URL> [...]]" >&2
18+
echo
19+
echo "Upload images to imgur and output their new URLs to stdout. Each one's" >&2
20+
echo "delete page is output to stderr between the view URLs." >&2
21+
echo
22+
echo "A filename can be - to read from stdin. If no filename is given, stdin is read." >&2
23+
echo
24+
echo "If xsel, xclip, or pbcopy is available, the URLs are put on the X selection for" >&2
25+
echo "easy pasting." >&2
26+
}
27+
28+
# Function to upload a path
29+
# First argument should be a content spec understood by curl's -F option
30+
function upload {
31+
curl -s -H "Authorization: Client-ID $client_id" -H "Expect: " -F "image=$1" https://api.imgur.com/3/image.xml
32+
# The "Expect: " header is to get around a problem when using this through
33+
# the Squid proxy. Not sure if it's a Squid bug or what.
34+
}
35+
36+
# Check arguments
37+
if [ "$1" == "-h" -o "$1" == "--help" ]; then
38+
usage
39+
exit 0
40+
elif [ $# -eq 0 ]; then
41+
echo "No file specified; reading from stdin" >&2
42+
exec "$0" -
43+
fi
44+
45+
# Check curl is available
46+
type curl &>/dev/null || {
47+
echo "Couldn't find curl, which is required." >&2
48+
exit 17
49+
}
50+
51+
clip=""
52+
errors=false
53+
54+
# Loop through arguments
55+
while [ $# -gt 0 ]; do
56+
file="$1"
57+
shift
58+
59+
# Upload the image
60+
if [[ "$file" =~ ^https?:// ]]; then
61+
# URL -> imgur
62+
response=$(upload "$file") 2>/dev/null
63+
else
64+
# File -> imgur
65+
# Check file exists
66+
if [ "$file" != "-" -a ! -f "$file" ]; then
67+
echo "File '$file' doesn't exist; skipping" >&2
68+
errors=true
69+
continue
70+
fi
71+
response=$(upload "@$file") 2>/dev/null
72+
fi
73+
74+
if [ $? -ne 0 ]; then
75+
echo "Upload failed" >&2
76+
errors=true
77+
continue
78+
elif echo "$response" | grep -q 'success="0"'; then
79+
echo "Error message from imgur:" >&2
80+
msg="${response##*<error>}"
81+
echo "${msg%%</error>*}" >&2
82+
errors=true
83+
continue
84+
fi
85+
86+
# Parse the response and output our stuff
87+
url="${response##*<link>}"
88+
url="${url%%</link>*}"
89+
delete_hash="${response##*<deletehash>}"
90+
delete_hash="${delete_hash%%</deletehash>*}"
91+
echo $url | sed 's/^http:/https:/'
92+
echo "Delete page: https://imgur.com/delete/$delete_hash"
93+
94+
# Append the URL to a string so we can put them all on the clipboard later
95+
clip+="$url"
96+
if [ $# -gt 0 ]; then
97+
clip+=$'\n'
98+
fi
99+
done
100+
101+
# Put the URLs on the clipboard if we can
102+
if type pbcopy &>/dev/null; then
103+
echo -n "$clip" | pbcopy
104+
elif [ $DISPLAY ]; then
105+
if type xsel &>/dev/null; then
106+
echo -n "$clip" | xsel
107+
elif type xclip &>/dev/null; then
108+
echo -n "$clip" | xclip
109+
else
110+
echo "Haven't copied to the clipboard: no xsel or xclip" >&2
111+
fi
112+
else
113+
echo "Haven't copied to the clipboard: no \$DISPLAY or pbcopy" >&2
114+
fi
115+
116+
if $errors; then
117+
exit 1
118+
fi

test/Spec.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ pdfBivariateNormal x y sigmax sigmay mux muy sigmaxy =
101101

102102
-- * Tests
103103

104-
main' = defaultMain $ tests "All tests" testPlot
104+
main = defaultMain $ tests "All tests" testPlot
105105

106-
main = defaultMain $ tests "Golden tests" testPlotGolden
106+
main' = defaultMain $ tests "Golden tests" testPlotGolden
107107

108108
main'' = defaultMain $ testGroup "All tests" [tests "Execution tests" testPlot
109109
, toneDownTests "Unreliable across machines" $ tests "Golden tests" testPlotGolden]
@@ -196,8 +196,7 @@ basicTests f = testGroup "Basic tests"
196196
]
197197

198198
fragileTests f = testGroup "Fragile tests"
199-
[ -- TODO Fails on circle ci (with latex)
200-
f "tex" mtex
199+
[ f "tex" mtex -- TODO Fails on circle ci (with latex)
201200
-- TODO Fails on circle ci (labels is not valid; matplotlib too old)
202201
, f "boxplot" mboxplot
203202
-- TODO Fails on circle ci (no violin plots; matplotlib too old)

0 commit comments

Comments
 (0)