The main scala codes:
implicit val randss = RandBasis.mt0val f = Figure()val p = f.subplot(0)val x = linspace(0.0,1.0)p += plot(x, x ^:^ 2.0)p += plot(x, x ^:^ 3.0, '.')p.xlabel = "x axis"p.ylabel = "y axis"f.saveas("lines.png")val p2 = f.subplot(2,1,1)val g = Gaussian(0,1)p2 += hist(g.sample(100000),100)p2.title = "A normal distribution"f.saveas("subplots.png")
Compile and run the codes.
Problem:
The sbt reported following error:
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException: mutation occurred during iteration
at scala.collection.mutable.MutationTracker$.checkMutations(MutationTracker.scala:43)
at scala.collection.mutable.CheckedIndexedSeqView$CheckedIterator.hasNext(CheckedIndexedSeqView.scala:47)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
at scala.collection.AbstractIterable.foreach(Iterable.scala:926)
at breeze.plot.Figure$$anon$1.run(Figure.scala:120)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Expected:
No error
NOTES:
From the codes, the following part may cause the issue:
for (plot <- plots) {contents.add(plot match { case Some(plot) => plot.panel; case None => new JPanel() })}
Steps:
Use following build.sbt file:
ThisBuild / scalaVersion := "2.13.7"
libraryDependencies += "org.scalanlp" %% "breeze" % "2.0.1-RC2"
libraryDependencies += "org.scalanlp" %% "breeze-viz" % "2.0.1-RC2"
The main scala codes:
implicit val randss = RandBasis.mt0
val f = Figure()
val p = f.subplot(0)
val x = linspace(0.0,1.0)
p += plot(x, x ^:^ 2.0)
p += plot(x, x ^:^ 3.0, '.')
p.xlabel = "x axis"
p.ylabel = "y axis"
f.saveas("lines.png")
val p2 = f.subplot(2,1,1)
val g = Gaussian(0,1)
p2 += hist(g.sample(100000),100)
p2.title = "A normal distribution"
f.saveas("subplots.png")
Compile and run the codes.
Problem: The sbt reported following error: Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException: mutation occurred during iteration at scala.collection.mutable.MutationTracker$.checkMutations(MutationTracker.scala:43) at scala.collection.mutable.CheckedIndexedSeqView$CheckedIterator.hasNext(CheckedIndexedSeqView.scala:47) at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563) at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561) at scala.collection.AbstractIterable.foreach(Iterable.scala:926) at breeze.plot.Figure$$anon$1.run(Figure.scala:120) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Expected: No error
NOTES: From the codes, the following part may cause the issue:
for (plot <- plots) {
contents.add(plot match { case Some(plot) => plot.panel; case None => new JPanel() })
}