Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding NewXYs func to plotter.go will be more convenient #363

Closed
linw1995 opened this issue May 30, 2017 · 1 comment
Closed

Adding NewXYs func to plotter.go will be more convenient #363

linw1995 opened this issue May 30, 2017 · 1 comment

Comments

@linw1995
Copy link

Adding this function will be more convenient.

  • Before adding, you create XYs like this
x := plotter.Values{0.1, 0.2, 0.3, 0.4}
y := plotter.Values{0.1, 0.2, 0.3, 0.4}
xys := make(plotter.XYs, x.Len())
for i := range xys {
	xys[i].X, xys[i].Y = x.Value(i), y.Value(i)
}
  • After adding, you can do more pretty
xys := plotter.NewXYs(x, y)

An Example of func NewXYs

// NewXYs returns an XYs that is a combination of the x, y Valuer,
// or an error if x's length is not equal to y's.
func NewXYs(x, y Valuer) XYs {
	if x.Len() != y.Len() {
		panic(fmt.Errorf("Len mismatch, %d != %d", x.Len(), y.Len()))
	}
	xys := make(XYs, x.Len())
	for i := range xys {
		xys[i].X, xys[i].Y = x.Value(i), y.Value(i)
	}
	return xys
}
@sbinet
Copy link
Member

sbinet commented May 30, 2017

a different take on #284 and #315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants