Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Jul 5, 2025

PR summary

Possibly closes #30230, though I'm unsure if it's a bit too hacky.

Introduce new private attributes so that apply_aspect can keep track of the previously set x/y-bounds. These attributes get reset when set_xlim/set_ylim are called, so further user updates to the limits are respected.

I ran the code from #30230 (comment) and messed about with the window shape. Everything seems fine.

If this seems good to others, I will add a test.

PR checklist

@QuLogic
Copy link
Member

QuLogic commented Sep 9, 2025

Did this not work?

@rcomer
Copy link
Member Author

rcomer commented Sep 9, 2025

It worked, but as I said above I wasn’t sure about it because it seemed a bit hacky. Since nobody commented, I figured everyone else was also not sure about it.

@rcomer
Copy link
Member Author

rcomer commented Sep 9, 2025

Possibly I could have labelled it differently to make it clearer I wanted feedback…

@rcomer rcomer reopened this Sep 9, 2025
@rcomer rcomer added status: needs comment/discussion needs consensus on next step and removed status: needs tests labels Sep 9, 2025
@timhoffm
Copy link
Member

timhoffm commented Sep 10, 2025

Random thoughts - sorry if this somewhat incoherent; I don't have a full overview of what is going on here either

I'm wondering whether we should strive for a more fundamental solution: The quantities xlim, ylim, aspect, box_aspect (explicit or via a fixed position box) over-specify the plot. Three out of four can be specified. The fourth is then induced. set_position already has the which parameter to distinguish between original and induced (active) value. Tracking that on every quantity seems impractical and I'd suspect that we won't be able to cover all combinations of given vs. induced parameters. Would it be more sustainable to track which of the quantities are set and at runtime calculate the real value? Though I'm not clear whether I'm overengineering this.


Fundamentally we have these cases

xlim / ylim aspect box_aspect
default (x) ~ x
set_aspect(..., adjustable="box") (x) x ~
set_aspect(..., adjustable="datalim") ~(*) x x

Legend:

  • ~ induced
  • x fixed / for limits: (x) fixed either by the user or inferred from data limits, but in both cases fixed as far as "induced" is concerned in the present context.

(*) The interesting part is in here. If data limits become variable, we must adapt one of xlim/ylim. And in theory one of them is enough. The bug is that we adjust both. My wild guess is that we keep one constant and adapt one as an induced effect to placate the above constraints. Then, constrained layout comes along and adjusts position/box_aspect, which results in another limit update, but that update does not know anymore that we intentionally modified one limit and not the other. Depending on the layout situation, it may adjust the other limit so that in the end both are modified.

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

Successfully merging this pull request may close these issues.

[BUG]: Neither explicit data limit is respected when constrained_layout is used together with set_aspect(..., "datalim")
3 participants