作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
有没有人有使用 plotinum 绘制具有对数刻度 y 轴的图形的经验?
我在 plotinum wiki 中找不到这样的例子:https://code.google.com/p/plotinum/wiki/Examples
最佳答案
根据 AlexAtNet 的回答,我可以绘制带有 y 轴的对数刻度直方图(以及其他图)。
我在这里分享我的代码片段,因为如果任何数据点有 y==0,plot.LogScale
会出现 panic ,然而,对于真实数据,这可能很难避免。我的解决方案是简单地实现我自己的 LogScale
。
func plotHist(data plotter.Values, title, xLabel, yLabel, imageFile string) {
log.Printf("Plotting to %s ...", imageFile)
p, e := plot.New()
if e != nil {
log.Fatalf("plot.New failed: %v", e)
}
h, e := plotter.NewHist(data, 50)
if e != nil {
log.Fatalf("plotter.NewHist failed: %v", e)
}
p.Add(h)
p.Title.Text = title
p.X.Label.Text = xLabel
p.Y.Label.Text = yLabel
p.Y.Min = 1
_, _, _, p.Y.Max = h.DataRange()
p.Y.Scale = LogScale
p.Y.Tick.Marker = plot.LogTicks
p.Add(plotter.NewGrid())
if e := p.Save(9, 6, imageFile); e != nil {
log.Fatalf("Cannot save image to %s: %v", imageFile, e)
}
log.Printf("Done plotting to %s.", imageFile)
}
func LogScale(min, max, x float64) float64 {
logMin := ln(min)
return (ln(x) - logMin) / (ln(max) - logMin)
}
func ln(x float64) float64 {
if x <= 0 {
x = 0.01
}
return math.Log(x)
}
输出图像如下所示:
关于go - 使用 plotinum 绘制具有对数刻度 y 轴的图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25775397/
我访问了Plotinum项目站点,以便在 Go 中生成绘图,但我无法在 Ubuntu 12.04 LTS 上安装该软件。我能够顺利安装 svgo 和 draw2d,但是 plot、plotter 和
有没有人有使用 plotinum 绘制具有对数刻度 y 轴的图形的经验? 我在 plotinum wiki 中找不到这样的例子:https://code.google.com/p/plotinum/w
我是一名优秀的程序员,十分优秀!