-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add histogram plot type, display bar chart labels on the right instea…
…d of overlapping.
- Loading branch information
Showing
15 changed files
with
296 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION = 1.1.2 | ||
VERSION = 1.1.3 | ||
|
||
APP := jp | ||
PACKAGES := $(shell go list -f {{.Dir}} ./...) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"reflect" | ||
|
||
"github.com/sgreben/jp/pkg/data" | ||
"github.com/sgreben/jp/pkg/draw" | ||
"github.com/sgreben/jp/pkg/plot" | ||
) | ||
|
||
func histogramData(xv []reflect.Value, nbins uint) (groups []string, counts []float64) { | ||
var x []float64 | ||
for i := range xv { | ||
if xv[i].IsValid() && xv[i].CanInterface() { | ||
xvi, ok := xv[i].Interface().(float64) | ||
if ok { | ||
x = append(x, xvi) | ||
} | ||
} | ||
} | ||
if len(x) == 0 { | ||
log.Fatal("no valid x values given") | ||
} | ||
bins := data.NewBins(x) | ||
bins.Number = int(nbins) | ||
if nbins == 0 { | ||
bins.ChooseSturges() | ||
} | ||
hist := data.Histogram(x, bins) | ||
groups = make([]string, len(hist)) | ||
counts = make([]float64, len(hist)) | ||
for i, b := range hist { | ||
groups[i] = b.String() | ||
counts[i] = float64(b.Count) | ||
} | ||
return | ||
} | ||
|
||
func histogram(xv []reflect.Value, c draw.Canvas, nbins uint) string { | ||
groups, counts := histogramData(xv, nbins) | ||
chart := plot.NewBarChart(c) | ||
chart.BarPaddingX = 0 | ||
data := new(data.Table) | ||
for _, g := range groups { | ||
data.AddColumn(g) | ||
} | ||
data.AddRow(counts...) | ||
return chart.Draw(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.