Skip to content

Commit b4d6af6

Browse files
committed
*** empty log message ***
1 parent ff54823 commit b4d6af6

File tree

5 files changed

+83
-67
lines changed

5 files changed

+83
-67
lines changed

README.md

Lines changed: 75 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
# Matplotlib
1+
![matplotlib contour plot](https://github.com/abarbu/matplotlib-haskell/raw/master/imgs/contour.png)
2+
3+
# Matplotlib for Haskell
24

35
[![Build Status](https://img.shields.io/circleci/project/github/abarbu/matplotlib-haskell.svg)](https://circleci.com/gh/abarbu/matplotlib-haskell)
46
[![Hackage](https://img.shields.io/hackage/v/matplotlib.svg)](https://hackage.haskell.org/package/matplotlib)
57

68
Haskell bindings to Python's Matplotlib. It's high time that Haskell had a
7-
fully-fledged plotting library!
9+
fully-fledged plotting library! Examples below.
810

9-
![matplotlib contour plot](https://github.com/abarbu/matplotlib-haskell/raw/master/imgs/contour.png)
11+
[Documentation is available on Hackage](https://hackage.haskell.org/package/matplotlib).
12+
13+
In GHCi:
14+
15+
```haskell
16+
:set -XExtendedDefaultRules
17+
import Graphics.Matplotlib
18+
onscreen $ contourF (\a b -> sin (a*pi/180.0) + cos (b*pi/180.0)) (-100) 100 (-200) 200 10
19+
```
1020

11-
[Documentation is available on Hackage](https://hackage.haskell.org/package/matplotlib). For
12-
more examples see the tests.
21+
Or in a standalone file
1322

1423
```haskell
1524
{-# LANGUAGE ExtendedDefaultRules #-}
1625

1726
import Graphics.Matplotlib
1827

19-
degreesRadians a = a * pi / 180.0
20-
21-
main :: IO ()
22-
main = do
23-
Right _ <- onscreen $ contourF (\a b -> sin (degreesRadians a) + cos (degreesRadians b)) (-100) 100 (-200) 200 10
24-
return ()
28+
main = onscreen $ contourF (\a b -> sin (a*pi/180.0) + cos (degreesRadians b)) (-100) 100 (-200) 200 10
2529
```
2630

2731
We need `-XExtendedDefaultRules` to avoid having to manually having to specify certain types.
@@ -32,14 +36,27 @@ You will need several python libraries to run this code which can be installed
3236
on Ubuntu machines with the following command:
3337

3438
```bash
35-
sudo apt-get install -y python3-pip python3-matplotlib python3-numpy python-mpltoolkits.basemap
39+
sudo apt-get install -y python3 python3-pip python3-matplotlib python3-numpy python3-tk python-mpltoolkits.basemap python3-scipy dvipng
40+
```
41+
42+
If you're using conda
43+
44+
```bash
45+
conda install matplotlib scipy tk
3646
```
3747

38-
If you have instructions for other machines or OSes let me know. We require
39-
`/usr/bin/python3` to be available; the path isn't configurable right now.
48+
If you have instructions for other machines or OSes let me know. We require the
49+
`python3` binary to be available somewhere in the PATH. We run with
50+
`env python3`.
4051

4152
Once you have the prerequisites you can install using the standard incantation
4253

54+
```bash
55+
stack install matplotlib
56+
```
57+
58+
or
59+
4360
```bash
4461
cabal install matplotlib
4562
```
@@ -89,76 +106,76 @@ different.
89106
[![pie][img_pie]][url_pie]
90107

91108
[img_violinplot]: https://i.imgur.com/iBOfnuL.png "violinplot"
92-
[url_violinplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L301
109+
[url_violinplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L299
93110
[img_contour]: https://i.imgur.com/KoAIf9Z.png "contour"
94-
[url_contour]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L225
111+
[url_contour]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L223
95112
[img_tex]: https://i.imgur.com/bR8r579.png "tex"
96-
[url_tex]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L260
113+
[url_tex]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L258
97114
[img_scatterhist]: https://i.imgur.com/9ZIVotE.png "scatterhist"
98-
[url_scatterhist]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L308
115+
[url_scatterhist]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L306
99116
[img_line-options]: https://i.imgur.com/Fahp7QA.png "line-options"
100-
[url_line-options]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L250
117+
[url_line-options]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L248
101118
[img_griddata]: https://i.imgur.com/SH83pJK.png "griddata"
102-
[url_griddata]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L605
119+
[url_griddata]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L603
103120
[img_pcolorlog]: https://i.imgur.com/ZLUoUqy.png "pcolorlog"
104-
[url_pcolorlog]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L498
121+
[url_pcolorlog]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L496
105122
[img_cumulative]: https://i.imgur.com/u5I8NYF.png "cumulative"
106-
[url_cumulative]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L218
123+
[url_cumulative]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L216
107124
[img_annotation]: https://i.imgur.com/9tdHiaT.png "annotation"
108-
[url_annotation]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L542
109-
[img_hist2DLog]: https://i.imgur.com/2fL8oEX.png "hist2DLog"
110-
[url_hist2DLog]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L278
125+
[url_annotation]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L540
111126
[img_density]: https://i.imgur.com/KS2OhbH.png "density"
112-
[url_density]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L242
127+
[url_density]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L240
113128
[img_line-function]: https://i.imgur.com/zkpfQqW.png "line-function"
114-
[url_line-function]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L244
129+
[url_line-function]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L242
115130
[img_boxplot]: https://i.imgur.com/KigvYSc.png "boxplot"
116-
[url_boxplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L295
131+
[url_boxplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L293
117132
[img_show-matrix]: https://i.imgur.com/ajY0A9l.png "show-matrix"
118-
[url_show-matrix]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L270
119-
[img_hinton]: https://i.imgur.com/m9a4IwL.png "hinton"
120-
[url_hinton]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L383
133+
[url_show-matrix]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L268
134+
[img_histMulti]: https://i.imgur.com/FxEI3EI.png "histMulti"
135+
[url_histMulti]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L335
121136
[img_streamplot]: https://i.imgur.com/IfHLmkC.png "streamplot"
122-
[url_streamplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L585
137+
[url_streamplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L583
123138
[img_pie]: https://i.imgur.com/ljgWXf6.png "pie"
124-
[url_pie]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L519
139+
[url_pie]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L517
125140
[img_corr]: https://i.imgur.com/GnBpDJL.png "corr"
126-
[url_corr]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L255
141+
[url_corr]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L253
127142
[img_projections]: https://i.imgur.com/IlK7Oy3.png "projections"
128-
[url_projections]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L248
129-
[img_stacked]: https://i.imgur.com/rWIyizX.png "stacked"
130-
[url_stacked]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L526
143+
[url_projections]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L246
144+
[img_scatter]: https://i.imgur.com/dceKS4I.png "scatter"
145+
[url_scatter]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L218
146+
[img_legend]: https://i.imgur.com/X46KiUJ.png "legend"
147+
[url_legend]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L271
131148
[img_density-bandwidth]: https://i.imgur.com/Qgjvrox.png "density-bandwidth"
132-
[url_density-bandwidth]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L239
149+
[url_density-bandwidth]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L237
133150
[img_bivariateNormal]: https://i.imgur.com/fTSfEzo.png "bivariateNormal"
134-
[url_bivariateNormal]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L468
135-
[img_histMulti]: https://i.imgur.com/FxEI3EI.png "histMulti"
136-
[url_histMulti]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L337
151+
[url_bivariateNormal]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L466
152+
[img_hinton]: https://i.imgur.com/m9a4IwL.png "hinton"
153+
[url_hinton]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L381
137154
[img_quadratic]: https://i.imgur.com/E4AafPD.png "quadratic"
138-
[url_quadratic]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L246
155+
[url_quadratic]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L244
139156
[img_histogram]: https://i.imgur.com/X37Rmy4.png "histogram"
140-
[url_histogram]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L215
157+
[url_histogram]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L213
141158
[img_polar]: https://i.imgur.com/4DAOrF1.png "polar"
142-
[url_polar]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L453
159+
[url_polar]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L451
143160
[img_quiver]: https://i.imgur.com/TcayDLc.png "quiver"
144-
[url_quiver]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L426
161+
[url_quiver]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L424
145162
[img_quiver-fancy]: https://i.imgur.com/NsOFHhx.png "quiver-fancy"
146-
[url_quiver-fancy]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L437
163+
[url_quiver-fancy]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L435
164+
[img_stacked]: https://i.imgur.com/rWIyizX.png "stacked"
165+
[url_stacked]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L524
147166
[img_spines]: https://i.imgur.com/BryQOY9.png "spines"
148-
[url_spines]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L355
149-
[img_errorbar]: https://i.imgur.com/gi0zEiz.png "errorbar"
150-
[url_errorbar]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L290
151-
[img_legend]: https://i.imgur.com/X46KiUJ.png "legend"
152-
[url_legend]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L273
167+
[url_spines]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L353
168+
[img_hist2DLog]: https://i.imgur.com/2fL8oEX.png "hist2DLog"
169+
[url_hist2DLog]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L276
153170
[img_integral]: https://i.imgur.com/PkepIKR.png "integral"
154-
[url_integral]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L399
155-
[img_scatter]: https://i.imgur.com/dceKS4I.png "scatter"
156-
[url_scatter]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L220
171+
[url_integral]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L397
172+
[img_errorbar]: https://i.imgur.com/gi0zEiz.png "errorbar"
173+
[url_errorbar]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L288
157174
[img_labelled-histogram]: https://i.imgur.com/lCVEpge.png "labelled-histogram"
158-
[url_labelled-histogram]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L227
175+
[url_labelled-histogram]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L225
159176
[img_eventplot]: https://i.imgur.com/UMT1yku.png "eventplot"
160-
[url_eventplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L283
177+
[url_eventplot]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L281
161178
[img_hists]: https://i.imgur.com/KurE2Sr.png "hists"
162-
[url_hists]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L374
179+
[url_hists]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L372
163180
[img_images]: https://i.imgur.com/R1fhDXC.png "images"
164-
[url_images]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L485
181+
[url_images]: https://github.com/abarbu/matplotlib-haskell/blob/master/test/Spec.hs#L483
File renamed without changes.

src/Graphics/Matplotlib/Internal.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ pyIncludes backend = ["import matplotlib"
343343
,"import matplotlib.image as mpimg"
344344
,"from mpl_toolkits.mplot3d import axes3d"
345345
,"import numpy as np"
346+
,"from scipy import interpolate"
346347
,"import os"
347348
,"import sys"
348349
,"import json"

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-9.6
1+
resolver: lts-13.13
22
packages:
33
- '.'
44
extra-deps:

test/Spec.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ testPlotGolden name fn =
139139
case (stderr, reads stderr) of
140140
("inf", _) -> return Nothing
141141
(_, [(x :: Double, _)]) ->
142-
if x < 35 then
142+
if x < 25 then
143143
return $ Just $ "Images very different; PSNR too low " ++ show x else
144144
return Nothing)))
145145
(BS.writeFile ref))
@@ -148,14 +148,12 @@ testPlotGolden name fn =
148148

149149
-- | Test one plot; right now we just test that the command executed without
150150
-- errors. We should visually compare plots somehow.
151-
testPlot name fn = testCase name $ tryit fn @?= Right ""
151+
testPlot' name fn = testCase name $ tryit fn @?= Right ""
152152
where tryit fn = unsafePerformIO $ withSystemTempFile "a.png" (\filename _ -> file filename fn)
153153

154154
-- | This generates examples from the test cases
155-
testPlot' name fn = testCase name $ tryit fn name @?= Right ""
155+
testPlot name fn = testCase name $ tryit fn name @?= Right ""
156156
where tryit fn name = unsafePerformIO $ do
157-
c <- code fn
158-
print c
159157
file ("/tmp/imgs/" ++ name ++ ".png") fn
160158

161159
basicTests f = testGroup "Basic tests"
@@ -336,11 +334,11 @@ mscatterHist = figure @@ [o1 0]
336334

337335
mhistMulti = subplots @@ [o2 "nrows" 2, o2 "ncols" 2]
338336
% setSubplot 0
339-
% histogram x nrBins @@ [o2 "normed" 1, o2 "histtype" "bar", o2 "color" ["red", "tan", "lime"], o2 "label" ["red", "tan", "lime"]]
337+
% histogram x nrBins @@ [o2 "density" 1, o2 "histtype" "bar", o2 "color" ["red", "tan", "lime"], o2 "label" ["red", "tan", "lime"]]
340338
% legend @@ [o2 "prop" $ lit "{'size': 10}"]
341339
% title "bars with legend"
342340
% setSubplot 1
343-
% histogram x nrBins @@ [o2 "normed" 1, o2 "histtype" "bar", o2 "stacked" True]
341+
% histogram x nrBins @@ [o2 "density" 1, o2 "histtype" "bar", o2 "stacked" True]
344342
% title "stacked bar"
345343
% setSubplot 2
346344
% histogram x nrBins @@ [o2 "histtype" "step", o2 "stacked" True, o2 "fill" False]
@@ -378,7 +376,7 @@ mhists = h 10 1.5
378376
where ns mu var = map (\x -> mu + x * var) $ take 1000 normals
379377
h mu var = histogram (ns mu var) 25 @@ [o2 "histtype" "stepfilled"
380378
,o2 "alpha" 0.8
381-
,o2 "normed" True]
379+
,o2 "density" True]
382380

383381
mhinton = mp # "ax.patch.set_facecolor('gray')"
384382
% setAspect @@ [o1 "equal", o1 "box"]

0 commit comments

Comments
 (0)