字符串类别名称与Wisp scala绘图库 [英] String category names with Wisp scala plotting library

查看:310
本文介绍了字符串类别名称与Wisp scala绘图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用 Wisp 绘制String类别的条形图。换句话说,我在我的repl中有一个字符串(键)和一个计数(值),我想有一个条形图的计数与键。



我不知道事情是否容易存在。我去了下面的黑客:

  val plot = bar(topWords.map(_._ 2).toList)
val axisType:com.quantifind.charts.highcharts.AxisType.Type =category
val newPlot = plot.copy(xAxis = plot.xAxis.map {
axisArray => axisArray。 map {_.copy(axisType = Option(axisType),
categories = Option(topWords.map(_._ 1)))}
})
/ pre>

但我不知道它是否工作,因为我没有找到一个方法可视化 newPlot



感谢您的帮助。



PS:我没有信誉创建wisp标签,但我会有...

解决方案

更新:在wisp 0.0.5或更高版本这将直接支持:

 列(List((alpha,1) ,(omega,5),(zeta,8)))



====



感谢您试用wisp(我是作者)。我认为你可能遇到的一个问题是命名你的变量 plot ,你覆盖了访问 plot Highcharts ,它允许绘制任何 Highchart 对象。 (现在我看到它,命名你的情节剧情是一个不幸的自然事情要做!)



我把这个作为一个github问题,都很常见。



这适用于我。对于竖线,我使用

  import com.quantifind.charts .highcharts._ 
val topWords = Array((alpha,14),(beta,23),(omega,18))
val numberedColumns = column(topWords.map _._ 2).toList)
val axisType:com.quantifind.charts.highcharts.AxisType.Type =category
val namedColumns = numberedColumns.copy(xAxis = numberedColumns.xAxis.map {
axisArray => axisArray.map {_.copy(axisType = Option(axisType),
categories = Option(topWords.map(_._ 1)))}
})
plot(namedColumns)

生成此可视化对象:



(您也可以考虑一次创建一个小节,他们)


I am trying to plot bars for String categories with Wisp. In other words, I have a string (key) and a count (value) in my repl and I want to have a bar chart of the count versus the key.

I don't know if something easy exists. I went as far as the following hack:

val plot = bar(topWords.map(_._2).toList)
val axisType: com.quantifind.charts.highcharts.AxisType.Type = "category"
val newPlot = plot.copy(xAxis = plot.xAxis.map {
  axisArray => axisArray.map { _.copy(axisType = Option(axisType),
                                      categories = Option(topWords.map(_._1))) }
})

but I don't know if it works because I don't find a way to visualize newPlot. Or maybe adding a method to the Wisp source implementing the above is the way to go?

Thanks for any help.

PS : I don't have the reputation to create the wisp tag, but I would have...

解决方案

Update: in wisp 0.0.5 or later this will be supported directly:

column(List(("alpha", 1), ("omega", 5), ("zeta", 8)))

====

Thanks for trying out wisp (I am the author). I think a problem that you may have encountered is by naming your variable plot, you overrode access to the plot method defined by Highcharts, which allows you to plot any Highchart object. (now that I see it, naming your plot "plot" is an unfortunately natural thing to do!)

I'm filing this as a github issue, as category names are very common.

This works for me. I used column for vertical bars:

import com.quantifind.charts.Highcharts._
val topWords = Array(("alpha", 14), ("beta", 23), ("omega", 18))
val numberedColumns = column(topWords.map(_._2).toList)
val axisType: com.quantifind.charts.highcharts.AxisType.Type = "category"
val namedColumns = numberedColumns.copy(xAxis = numberedColumns.xAxis.map {
  axisArray => axisArray.map { _.copy(axisType = Option(axisType),
                                       categories = Option(topWords.map(_._1))) }
})
plot(namedColumns)

producing this visualization:

(You could also consider creating one bar at a time, and use the legend to name them)

这篇关于字符串类别名称与Wisp scala绘图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆