0

In numpy, it is possible to visualize an array of numeric values by using imshow. I wish to produce similar images in Haskell, including displaying axes, titles, and so on. Additionally, it would be useful if it were possible to overlay e.g. geometric shapes on top of the visualized array.

I see many libraries that might already implement this kind of functionality, but can't find it myself. If it does not exist, where would be my best bet to start ?

oneway
  • 753
  • 1
  • 5
  • 9
  • possible duplicate of [Which haskell library will let me save a 2D array/vector to a png/jpg/gif... file?](http://stackoverflow.com/questions/5191329/which-haskell-library-will-let-me-save-a-2d-array-vector-to-a-png-jpg-gif-fil) – 9000 Dec 03 '14 at 18:23

3 Answers3

1

The answers to this SO question contain some suggestions and code examples:

Community
  • 1
  • 1
ErikR
  • 51,541
  • 9
  • 73
  • 124
0

imshow doesn't come from numpy, it comes from matplotlib. matplotlib is a native Python library, so to use it in a Haskell program you'd need to get to it through the Python c API. There's already a library of Haskell bindings to the Python c API, cpython. This would probably be a bit tricky to use because it can't marshall functions, and, although I'm not familiar with matplotlib, plotting libraries typically take functions for features such as tick and label formatting.

Cirdec
  • 24,019
  • 2
  • 50
  • 100
0

From the plot package

ms :: Matrix Double
ms = buildMatrix 64 64 (\(x,y) -> sin (2*2*pi*(fromIntegral x)/64) * cos (5*2*pi (fromIntegral y)/64))

mat_fig = do
        setPlots 1 1
        withPlot (1,1) $ do 
                         setDataset ms
                         addAxis XAxis (Side Lower) $ setTickLabelFormat "%.0f"
                         addAxis YAxis (Side Lower) $ setTickLabelFormat "%.0f"
                         setRangeFromData XAxis Lower Linear
                         setRangeFromData YAxis Lower Linear

You can also add title and subtitle and you can use annotations to draw arbitrary shapes on the plot area.

vivian
  • 1,434
  • 1
  • 10
  • 13