Log scale

21 views
Skip to first unread message

Ethan Burns

unread,
Feb 17, 2014, 1:31:52 PM2/17/14
to plotinum...@googlegroups.com
Hello Everyone,

I just added two small changes to the dev branch of Plotinum to support log scale axes.  Would anyone mind giving the code a quick review before I pull it into the default branch in a day or two?  You can find the changes here: https://code.google.com/p/plotinum/source/list?name=dev.  I tested them with this program:

// +build ignore

// A simple test program to test plotters.
package main

import (
"math"
"math/rand"

)

func main() {
p, err := plot.New()
if err != nil {
panic(err)
}
p.Title.Text = "Functions"
p.X.Label.Text = "X"
p.Y.Label.Text = "Y"
p.Y.Scale = plot.LogScale
p.Y.Tick.Marker = plot.LogTicks

exp := plotter.NewFunction(func(x float64) float64 { return math.Pow(10, x) })

p.Add(exp)
p.Legend.Add("10^x", exp)
p.Legend.ThumbnailWidth = vg.Inches(0.5)

err = plotutil.AddLinePoints(p,
"First", randomPoints(15),
"Second", randomPoints(15),
"Third", randomPoints(15))
if err != nil {
panic(err)
}

if err := p.Save(4, 4, "exp2.eps"); err != nil {
panic(err)
}
}

// randomPoints returns some random x, y points.
func randomPoints(n int) plotter.XYs {
pts := make(plotter.XYs, n)
for i := range pts {
if i == 0 {
pts[i].X = rand.Float64()
} else {
pts[i].X = pts[i-1].X + rand.Float64()
}
pts[i].Y = pts[i].X + 100*rand.Float64()
}
return pts
}



Thanks,
Ethan

Ethan Burns

unread,
Feb 17, 2014, 1:42:40 PM2/17/14
to plotinum...@googlegroups.com
The tick marker needs work. I think it's completely broken if your axis doesn't span a power of 10. Any ideas?


Ethan

Ethan Burns

unread,
Feb 17, 2014, 4:54:11 PM2/17/14
to plotinum...@googlegroups.com
I made one more commit for tonight.  The tick marker should now behave better.  I decided to panic when attempting to take the log of values <= 0.  This seems inline with how GNU plot does it.  Enjoy.  Please let me know if anything is broken or could be improved.  I plan to merge this into the default branch in a few days.


Also, here's a more reasonable test program:
package main

import (
"math"
"math/rand"
)

func main() {
rand.Seed(int64(0))

p, err := plot.New()
if err != nil {
panic(err)
}

p.Title.Text = "Plotutil example"
p.X.Label.Text = "X"
p.Y.Label.Text = "Y"

err = plotutil.AddLinePoints(p,
"First", randomPoints(10),
"Second", randomPoints(10),
"Third", randomPoints(10))
if err != nil {
panic(err)
}
p.Y.Scale = plot.LogScale
p.Y.Tick.Marker = plot.LogTicks

if err := p.Save(4, 4, "points.eps"); err != nil {
panic(err)
}
}

// randomPoints returns some random x, y points.
func randomPoints(n int) plotter.XYs {
pts := make(plotter.XYs, n)
for i := range pts {
if i == 0 {
pts[i].X = rand.Float64()
} else {
pts[i].X = pts[i-1].X + rand.Float64()
}
pts[i].Y = 0.00001 * math.Pow(10, pts[i].X+rand.Float64())
}
return pts
}



Ethan

Dan Kortschak

unread,
Feb 17, 2014, 5:14:55 PM2/17/14
to Ethan Burns, plotinum...@googlegroups.com
For a non-hg user, how do I add a remote branch with mercurial?

Ethan Burns

unread,
Feb 17, 2014, 5:16:16 PM2/17/14
to Dan Kortschak, plotinum...@googlegroups.com
I'm not sure. I'm more of a git user.
Reply all
Reply to author
Forward
0 new messages