Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra X-axis padding when there is a label #779

Closed
JAicewizard opened this issue Jun 3, 2024 · 3 comments · Fixed by #780
Closed

Extra X-axis padding when there is a label #779

JAicewizard opened this issue Jun 3, 2024 · 3 comments · Fixed by #780

Comments

@JAicewizard
Copy link

What are you trying to do?

Create a graph with 0-padded axis and axis names

What did you do?

package main

import (
	"gonum.org/v1/plot"
	"gonum.org/v1/plot/plotter"
)

type (
	benchmarkSequence struct {
	}
)

func main() {
	p := plot.New()
	p.X.Padding = 0
	p.Y.Padding = 0
	p.X.Label.Text = "P (Passingrate)" // comment this line to get expected result

	line, err := plotter.NewLine(benchmarkSequence{})
	if err != nil {
		panic(err)
	}
	p.Add(line)
	err = p.Save(500, 500, "plotLogo.png")
	if err != nil {
		panic(err)
	}
}

// Implement plot.XYer for benchmarkSequence
func (s benchmarkSequence) Len() int {
	return 99
}

func (s benchmarkSequence) XY(i int) (float64, float64) {
	return float64(i) / 100, float64(i) / 100
}

What did you expect to happen?

plotLogo

What actually happened?

plotLogo

What version of Go and Gonum/plot are you using?

I just fetched gonum 0.13, and im using go 1.22.3 (linux/amd64)

Does this issue reproduce with the current master?

Did not try, but there does not seem to be any real changes in master

@JAicewizard
Copy link
Author

Actually you can see that with the expected result the Y-axis is also misaligned

@kortschak
Copy link
Member

It looks to me like the descents should not be being used in calculating the height of the axis. If I do this

diff --git a/axis.go b/axis.go
index 3b275ad..451acce 100644
--- a/axis.go
+++ b/axis.go
@@ -235,7 +235,6 @@ type horizontalAxis struct {
 // size returns the height of the axis.
 func (a horizontalAxis) size() (h vg.Length) {
        if a.Label.Text != "" { // We assume that the label isn't rotated.
-               h += a.Label.TextStyle.FontExtents().Descent
                h += a.Label.TextStyle.Height(a.Label.Text)
                h += a.Label.Padding
        }

I get this
plotLogo

@sbinet WDYT?

@sbinet
Copy link
Member

sbinet commented Jun 12, 2024

(apologies for the belated answer. with the events unfolding in France, I have a limited bandwith for software...)

SGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants