sciapp / gr

GR framework: a graphics library for visualisation applications
Other
328 stars 54 forks source link

GRM - histogram gives me an error #115

Closed mantielero closed 4 years ago

mantielero commented 4 years ago

When I try to create an histogram using GRM I get the following error:

invalid range
GKS: Possible loss of precision in routine SET_WINDOW
GKS: Rectangle definition is invalid in routine SET_WINDOW
origin outside current window
IngoMeyer441 commented 4 years ago

Thanks for your bug reports, they help to get GRM to a usable state. Could you attach a code example to reproduce the effect? Which version of GR did you use for your test?

mantielero commented 4 years ago

I am using aur/gr-framework 0.49.0-1 from ArchLinux.

Regarding the code, it is Nim but I believe it is understandable:

import gr
import sequtils, sugar, math, random

let n = 100
var x = newSeq[float](n)

for i in 0..<n:
  x[i] = rand(1.0) * 2.0 - 1.0 

histogram(x, nbins=19)

discard readLine(stdin)
grm_finalize()

Within histogram I do exactly the same as with the other examples that they are working. Internally in Nim, the function histogram does:

proc histogram*(x:seq[float]; nbins:int = 10) =
  ##[
  Histogram
  ]##
  var args = grm_args_new()
  discard grm_args_push(args, "kind".cstring, "s".cstring, "hist".cstring) 
  discard grm_args_push(args, "x".cstring, "nD".cstring, x.len.cint, cast[ptr cdouble](x[0].unsafeAddr) )
  discard grm_args_push(args, "nbins".cstring, "i".cstring, nbins.cint )

  discard grm_plot(args)
  grm_args_delete(args)

The only thing that I do differently to the other functions is the line:

discard grm_args_push(args, "nbins".cstring, "i".cstring, nbins.cint )
JonasClever commented 4 years ago

GRM expected the histogram to be already calculated by the wrapper. Therefore x and y values. Since it was planned to change this behaviour anyway we changed it in this commit, meaning it is fixed in todays release v0.50.0.