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

Bug in empty plot: IndexOutOfBoundsException #194

Closed
Unaimend opened this issue Jul 14, 2023 · 3 comments
Closed

Bug in empty plot: IndexOutOfBoundsException #194

Unaimend opened this issue Jul 14, 2023 · 3 comments
Milestone

Comments

@Unaimend
Copy link

Sry for the not-so-descriptive title. Anyway, akin to R I tried following code which I copied and changed from [1]

%use lets-plot
fun meshgridPoints(x:List<Double>, y:List<Double>):List<Pair<Double, Double>> {
  val xSer = y.flatMap { x }
  var yInd = -1
  val ySer = y.flatMap {
      yInd++
      List(x.size) {y[yInd]}
  }
  return xSer.zip(ySer)
}

val gridPoints = meshgridPoints(
    generateSequence(0.0, {it + 6.0/50} ).takeWhile { it <= 5.0 }.toList(),
    generateSequence(0.0, {it + 6.0/40} ).takeWhile { it <= 5.0 }.toList())
fun g(x:Double, y:Double): Double {
    return sin(x).pow(10) + cos(10 + y * x) * cos(x)
}

val X = gridPoints.map { it.first }
val Y = gridPoints.map { it.second }
val Z = gridPoints.map { g(it.first, it.second) }


val p = letsPlot {x=X; y=Y; fill=Z}
p + geomTile() + scaleFillHue()
p

You might notice that I added a p in the last line, akin to R. This results in the following error

Internal error: IndexOutOfBoundsException: index: 0, size 0.

Removing the p again results in working code. I filed this issue due to the quite undescriptive error message.

Thank you for the nice library and your time
Thomas

Discussion on Kotlin Slack: https://kotlinlang.slack.com/archives/C05333T208Y/p1689348252503279

[1] https://nbviewer.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/contours.ipynb

@alshan alshan added this to the 2023Q3 milestone Jul 14, 2023
@alshan
Copy link
Collaborator

alshan commented Jul 14, 2023

Thank you for reporting this.
Please note however that by adding p as a last expr. in cell you discard the value of the expression next to the last.
Effectively, you are trying to visualize letsPlot {x=X; y=Y; fill=Z} which is of course an empty plot (no layers).

@ileasile
Copy link
Member

ileasile commented Jul 14, 2023

@alshan yes, there was normal error message before (api=4.2.0, lib=3.0.0, js=3.0.0 and api=4.3.0, lib=3.1.0, js=3.1.0 are ok, latest version is broken)
image

@alshan alshan changed the title Bug in ploty Bug in empty plot: IndexOutOfBoundsException Aug 9, 2023
@alshan
Copy link
Collaborator

alshan commented Aug 24, 2023

Fixed in 4.4.2

@alshan alshan closed this as completed Aug 24, 2023
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

3 participants