我想在Zeppelin中以直方图的形式显示我的结果。我发现了plotly。我的代码是用Scala编写的,我想知道如何使用Scala将plotly纳入Zeppelin。或者是否有更好的方法(库)可以用于在Zeppelin(Scala)中绘制直方图?
我想在Zeppelin中以直方图的形式显示我的结果。我发现了plotly。我的代码是用Scala编写的,我想知道如何使用Scala将plotly纳入Zeppelin。或者是否有更好的方法(库)可以用于在Zeppelin(Scala)中绘制直方图?
plotTemp.registerTempTable("plotTemp")
Then switch to the SQL interpreter in a new window
%sql
select degree, count(1) nInBin
from plotTemp
group by degree
order by degree
您可以点击条形图图标,然后您应该能看到您想要的内容。
在尝试了几乎所有现有的解决方案之后,我最终选择了vegas-viz。如果您查看他们在GitHub上的项目页面,他们声称是“Scala + Spark的遗失MatPlotLib”。尽管这在目前听起来有点夸张,但该库确实有效且表现良好。
这是我建议在Zeppelin的Spark解释器中绘制条形图(基本上就是直方图所需)的步骤:
import dependencies (please check the vegas maven repository for the latest versions)
%dep
z.load("org.vegas-viz:vegas_2.11:0.3.11")
z.load("org.vegas-viz:vegas-spark_2.11:0.3.11")
import packages
import vegas._
import vegas.render.WindowRenderer._
draw chart
val plot = Vegas("Sample Column Chart")
.withData(
Seq(
Map("country" -> "USA", "population" -> 314),
Map("country" -> "UK", "population" -> 64),
Map("country" -> "DK", "population" -> 80)
)
)
.encodeX("country", Nom)
.encodeY("population", Quant)
.mark(Bar)
plot.show
The result should be similar to the image below:
you can even draw an image directly from a DataFrame if you have added vegas-spark among the dependencies (see point 1.) but you also need an extra import for this to work:
import vegas.sparkExt._
val df = Seq(
("USA", 314),
("UK", 64),
("DK", 80)
).toDF("country", "population")
val plot = Vegas("Sample Column Chart", width=600, height=320)
.withDataFrame(df)
.encodeX("country", Nom)
.encodeY("population", Quant)
.mark(Bar)
plot.show
import com.knockdata.spark.highcharts._
import com.knockdata.spark.highcharts.model._
highcharts(bank
.series("x" -> "age", "y" -> count("*"))
.orderBy(col("age"))
)
.chart(Chart.column)
.plotOptions(new plotOptions.Column().groupPadding(0).pointPadding(0).borderWidth(0))
.plot()