Bluemix Apache Spark服务 - 为scala绘图?

时间:2015-12-17 14:15:56

标签: scala apache-spark plot ibm-cloud jupyter

有没有办法在Jupyter笔记本中为Scala使用任何类型的绘图,如Matplotlib for Python?

感谢。

1 个答案:

答案 0 :(得分:0)

对于Bluemix上的Scala笔记本,我主要使用两个绘图库(按照优先顺序):

  1. Brunel [推荐]:我建议使用Brunel,因为它已经安装在Bluemix的笔记本服务器中。这允许您使用Brunel魔术命令 %% brunel
  2. 
        // Example Scala Cell invocation
        %%brunel
        data('https://raw.githubusercontent.com/Brunel-Visualization/Brunel/master/python/examples/data/whiskey.csv') point x(Rating) y(Age) bin(Rating,Age)
    
    

    Brunel Point Bin Visualization

    供参考,以下是一些示例Scala笔记本示例:example 1 example 2

    1. Lightning-Viz:对于Lightning-Viz,您需要我为了与Scala 2.10兼容而重新编译的自定义客户端jar lightning-scala_2.10-0.2.0.jar。在您的Scala单元格中,您可以执行以下操作...
    2. 
          /** Load Lightning Scala Client for Visualizations */
          %AddJar https://github.com/joshisa/lightning-scala/raw/master/dist/lightning-scala_2.10-0.2.0.jar -f
          import org.viz.lightning._
          import scala.util.Random
          // host should not contain a trailing slash
          val lgn = Lightning(host="https://lightningviz.mybluemix.net");
          lgn.auth = None
          lgn.createSession()
          println("Woot!, we have a lightning viz object.  Bazinga!");
          println("");
          val x = Array.fill(100)(Random.nextDouble());
          val y = Array.fill(100)(Random.nextDouble());
          val somegroup = Array.fill(100)(Random.nextFloat() * 5).map(_.toInt);
          val somelabels = (Array("point 0", "point 1", "point 2", "point 3", "point 4", "point 5", "point 6", "point 7", "point 8", "point 9", "point 10", 
                                  "point 11", "point 12", "point 13", "point 14", "point 15", "point 16", "point 17", "point 18", "point 19", "point 20", 
                                  "point 21", "point 22", "point 23", "point 24", "point 25", "point 26", "point 27", "point 28", "point 29", "point 30", 
                                  "point 31", "point 32", "point 33", "point 34", "point 35", "point 36", "point 37", "point 38", "point 39", "point 40", 
                                  "point 41", "point 42", "point 43", "point 44", "point 45", "point 46", "point 47", "point 48", "point 49", "point 50", 
                                  "point 51", "point 52", "point 53", "point 54", "point 55", "point 56", "point 57", "point 58", "point 59", "point 60", 
                                  "point 61", "point 62", "point 63", "point 64", "point 65", "point 66", "point 67", "point 68", "point 69", "point 70", 
                                  "point 71", "point 72", "point 73", "point 74", "point 75", "point 76", "point 77", "point 78", "point 79", "point 80", 
                                  "point 81", "point 82", "point 83", "point 84", "point 85", "point 86", "point 87", "point 88", "point 89", "point 90", 
                                  "point 91", "point 92", "point 93", "point 94", "point 95", "point 96", "point 97", "point 98", "point 99"));
          val somesize = Array.fill(100)(Random.nextDouble() * 20 + 5);
          val xaxis = "example x-axis label";
          val yaxis = "example y-axis label";
          val alpha = Array(0.6);
          val viz = lgn.scatter(x, y, somegroup, labels=somelabels, alpha=alpha, size=somesize, xaxis=xaxis, yaxis=yaxis);
          val vizhtml = viz.getHTML
          kernel.magics.html(s"""
            ${vizhtml}
          """);
      
      

      Lightning-Viz Scatterplot