gonum / plot

A repository for plotting and visualizing data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

plot: cannot use fnt.Font() (type *truetype.Font) as type *sfnt.Font in field value

haswalt opened this issue · comments

What are you trying to do?

Use plot to draw a simple line

What did you do?

This simple example script demonstrates a contrived example based on working code.

import (
	"gonum.org/v1/plot"
	"gonum.org/v1/plot/plotter"
	"gonum.org/v1/plot/vg"
)

func main() {
  p, err := plot.New()
  if err != nil {
	return err
  }

  plotter.DefaultLineStyle.Width = vg.Points(1)

  xys := ...
  l, _ := plotter.NewLine(xys)
  p.Add(l)

  p.HideX()
  p.HideY()

  p.Save(1024, 540, "out.png")
}

However when trying to update dependencies within the project (using go modules).

go get -u ./...

What did you expect to happen?

All modules to update and the go.mod and go.sum to be updated.

What actually happened?

This error is output:

# gonum.org/v1/plot/text
../../../Go/pkg/mod/gonum.org/v1/plot@v0.8.1/text/latex.go:36:3: cannot use fnt.Font() (type *truetype.Font) as type *sfnt.Font in field value
../../../Go/pkg/mod/gonum.org/v1/plot@v0.8.1/text/latex.go:37:3: cannot use fnt.Font() (type *truetype.Font) as type *sfnt.Font in field value
../../../Go/pkg/mod/gonum.org/v1/plot@v0.8.1/text/latex.go:38:3: cannot use fnt.Font() (type *truetype.Font) as type *sfnt.Font in field value
../../../Go/pkg/mod/gonum.org/v1/plot@v0.8.1/text/latex.go:64:3: cannot use sty.Font.Font() (type *truetype.Font) as type *sfnt.Font in field value
../../../Go/pkg/mod/gonum.org/v1/plot@v0.8.1/text/latex.go:65:3: cannot use sty.Font.Font() (type *truetype.Font) as type *sfnt.Font in field value
../../../Go/pkg/mod/gonum.org/v1/plot@v0.8.1/text/latex.go:66:3: cannot use sty.Font.Font() (type *truetype.Font) as type *sfnt.Font in field value

What version of Go and Gonum/plot are you using?

go version go1.15.8 darwin/amd64
gonum.org/v1/plot v0.8.1

Does this issue reproduce with the current master?

yes, it's a known issue that should be resolved with the new tagged release of gonum/gonum and gonum/plot.

in the meantime, a recipe is provided here:

@sbinet can you give me a couple more pointers, i.e. a working replace?

I'm having issues with invalid versions coming from LaTex.

For anyone else hitting this problem here is the replaces I had to add:

replace gonum.org/v1/gonum => gonum.org/v1/gonum v0.8.1-0.20210203072158-6eb8ed55bbee

replace github.com/go-latex/latex => github.com/go-latex/latex v0.0.0-20201211121425-9504e023060c

Specifcally this uses gonum master but a latex version before truetype fronts were removed.

could you try with the latest gonum/plot revision (#671) ?
it should fix the go-latex problem.

that fixed it for me (tm):

$> cd /somewhere
$> cat > main.go
package main

import (
 _ "gonum.org/v1/plot"
 _ "gonum.org/v1/gonum/mat"
)

func main() {}
^C

$> go mod
[11:48 binet@zoidberg gplt669]$ go mod init issue669
go: creating new go.mod: module issue669
go: to add module requirements and sums:
	go mod tidy

$> go mod tidy
go: finding module for package gonum.org/v1/plot
go: finding module for package gonum.org/v1/gonum/mat
go: found gonum.org/v1/gonum/mat in gonum.org/v1/gonum v0.8.2
go: found gonum.org/v1/plot in gonum.org/v1/plot v0.8.1

$> go get -u  gonum.org/v1/plot@master
go get: upgraded github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af => v0.0.0-20200725142600-7a3c8b57fecb
go get: upgraded golang.org/x/image v0.0.0-20200618115811-c13761719519 => v0.0.0-20210220032944-ac19c3e999fb
go get: upgraded gonum.org/v1/plot v0.8.1 => v0.8.2-0.20210223103650-0101d3258640

$> cat go.mod
module issue669

go 1.17

require (
	github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb // indirect
	github.com/jung-kurt/gofpdf v1.16.2 // indirect
	golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
	gonum.org/v1/gonum v0.8.2
	gonum.org/v1/plot v0.8.2-0.20210223103650-0101d3258640
)

$> go build -v .
issue669

should be fixed now that v0.9.0 has been tagged.

(feel free to reopen otherwise)