gpt4 book ai didi

scala - Bluemix Apache Spark 服务 - 为 scala 绘图?

转载 作者:行者123 更新时间:2023-12-02 04:44:30 27 4
gpt4 key购买 nike

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

谢谢。

最佳答案

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

  1. Brunel [推荐]:我推荐使用 Brunel,因为它已经安装在 Bluemix 的笔记本服务器中。这允许您使用 Brunel 魔术命令 %%brunel:
    // 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,您需要一个自定义客户端 jar lightning-scala_2.10-0.2.0.jar为了与 Scala 2.10 兼容,我重新编译了它。在您的 Scala 单元中,您会做这样的事情......
    /** 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

关于scala - Bluemix Apache Spark 服务 - 为 scala 绘图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com