Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

plotter: Is current "uniformness" of heatmap coloring intentional?

未关闭
#777 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
go

调研方向

从 plotter/heat.go 中热图颜色缩放相关的注释和代码开始,重点查看有关调色板缩放和单元格颜色选择的引用行。使用 gonum.org/v1/plot v0.14.0 设置运行提供的 TestHeatMap 复现程序,并将生成的图像与所述预期进行比较。当预期的颜色分布得到解决,并且该行为已被覆盖或明确时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

What are you trying to do?

Drawing heatmap.

What did you do?
func TestHeatMap(t *testing.T) {
	m := offsetUnitGrid{
		XOffset: -2,
		YOffset: -1,
		Data: mat.NewDense(3, 4, []float64{
			1, 2, 3, 4,
			5, 6, 7, 8,
			9, 10, 11, 12,
		}),
	}
	pal := myPalette{}
	h := plotter.NewHeatMap(m, pal)

	p := plot.New()
	p.Add(h)

	p.X.Padding = 0
	p.Y.Padding = 0

	img := vgimg.New(250, 175)
	dc := draw.New(img)
	p.Draw(dc)
	w, err := os.Create("golden_files/heatMap.png")
	if err != nil {
		log.Panic(err)
	}
	png := vgimg.PngCanvas{Canvas: img}
	if _, err = png.WriteTo(w); err != nil {
		t.Fatal(err)
	}
}

type myPalette struct{}

func (myPalette) Colors() []color.Color {
	return []color.Color{
		color.RGBA{R: 255, A: 255},
		color.RGBA{G: 255, A: 255},
		color.RGBA{B: 255, A: 255},
		color.RGBA{R: 255, G: 255, A: 255},
	}
}

// offsetUnitGrid is copied from https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat_test.go#L21
What did you expect to happen?

Each color is used "uniformly". I consider 3 cells for each colors (3 * 4 = 12) is "unform".
Following code comments says palette is scaled uniformly across the data range.
https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat.go#L157

What actually happened?

2 cells for red, 4 cells for green, 4 cells for blue, 2 cells for yellow. This doesn't look uniform to me.
heatMap

Probably first color and last color have half chance to be used compared the other colors.
In my thought, following should be ps := float64(len(pal)) / (h.Max - h.Min)
https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat.go#L157-L158
and following shouldbe col = pal[int((v-h.Min)*ps)] to get uniform.
https://github.com/gonum/plot/blob/b4fdc267610216647ec69681d47e431cf5bbed23/plotter/heat.go#L222-L224

What version of Go and Gonum/plot are you using?
go version go1.22.0 darwin/arm64
gonum.org/v1/plot v0.14.0
Does this issue reproduce with the current master?

Not experimented yet. Maybe yes.

主要语言
Go
星标
3k
派生
202
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

gonum/plot 的其他 Issue

查看 gonum/plot 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。