An open API service indexing awesome lists of open source software.

https://github.com/jborrow/mplgo

A small golang package for using matplotlib colour maps
https://github.com/jborrow/mplgo

Last synced: 3 months ago
JSON representation

A small golang package for using matplotlib colour maps

Awesome Lists containing this project

README

        

mplgo
=====

A small package for using `matplotlib` colour maps in `golang`.

Works by shelling out to `python` and extracting a color map directly from matplotlib,
to a `golang` struct. NaN values map to transparent white.

Example Usage
-------------

Download the package:

```
go get github.com/jborrow/mplgo
```

```go
package main

import (
"image/png"
"log"
"os"
"github.com/jborrow/mplgo"
)

func MapArrayToPNG(m mplgo.ColorMap, in [][]float64, file_name string) error {
f, err := os.Create(file_name)
if err != nil {
return err
}
defer f.Close()

// Encode the image to PNG and save it to the file
if err := png.Encode(f, m.MapArrayToImage(in)); err != nil {
panic(err)
}

return nil
}

func main() {
colorMap, err := mplgo.GetCmap("viridis", 128)

if err != nil {
log.Fatal(err)
}

// Example data
data := make([][]float64, 128)

for i := range data {
line := make([]float64, 128)
for j := range line {
line[j] = (float64(i) / 128.0 * float64(j) / 128.0)
}
data[i] = line
}

// Write to the world
err = MapArrayToPNG(colorMap, data, "hello_world.png")

if err != nil {
log.Fatal(err)
}

return
}
```