Skip to content

Separate x and y flags for AxisItem.setLogMode#2081

Merged
j9ac9k merged 3 commits intopyqtgraph:masterfrom
max-radin:axis-item-setlog
Nov 14, 2021
Merged

Separate x and y flags for AxisItem.setLogMode#2081
j9ac9k merged 3 commits intopyqtgraph:masterfrom
max-radin:axis-item-setlog

Conversation

@max-radin
Copy link
Copy Markdown
Contributor

This fix allows the example code from #997 to be run. I also checked that the logAxis.py example looks the same after this change.


```bash
python -m pytest examples tests
python -m pytest pyqtgraph/examples tests
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

@NilsNemitz
Copy link
Copy Markdown
Contributor

Hi @max-radin,

That is interesting, because I think the code that seems to break here is newer than the issue #997.
Ooops. Might have broken something there.

I am currently looking at the log-mode propagation from another angle... I currently think that it might be better to tell the ViewBox about the requested log mode settings from inside PlotItem.updateLogMode that should have the information for both axes. The AxisItems don't really have a need to know about both orientations.

Doesn't each of the four potential axes set both x and y mode individually, now?

@NilsNemitz
Copy link
Copy Markdown
Contributor

NilsNemitz commented Nov 13, 2021

Ah, sorry, I missed the actual broken bit here.

While I am not sure if setLogMode is ever called directly, do you think this can work so that

  • two arguments are treated as x and y, and AxisItem.logMode is extracted from the correct one, like you have now
  • a single argument directly controls AxisItem.logMode as before
    ?

@max-radin
Copy link
Copy Markdown
Contributor Author

Hi @NilsNemitz, one way we could support the old single-argument behavior would be to do something like

def setLogMode(self, *args, **kwargs):
  if len(args) == 1 or 'log' in kwargs:
    # do the old thing
  else:
    # do the new thing

That way calling setLogMode(True) will control log mode along the direction of the axis while still allowing setLogMode(x=True) to control log mode in the x direction.

Pros:

  • Backwards compatibility with any user code that called AxisItem.logMode
  • Provides an easy way to set the log mode along an axis without having to check its orientation

Cons:

  • The behavior of AxisItem.logMode will be different from PlotItem.logMode.
  • The function signature and logic in AxisItem.logMode will be a bit more complicated.

Do you think this makes sense to do? I'm pretty new to the codebase so I don't really have a sense of how these methods typically get used.

@NilsNemitz
Copy link
Copy Markdown
Contributor

I think that is a good idea.
You probably do not need to check for the log keyword, that is probably not commonly used in a single-parameter function call.
So the simple distinction of one argument / two arguments might make it work.
Then it has the same functionality as other items when called by PlotItem (with two parameters).
And the old single parameter, possibly user-accessible interface still works to set log mode along the axis alignment.

@max-radin
Copy link
Copy Markdown
Contributor Author

@NilsNemitz just pushed a commit that adds backwards compatibility for the single argument case. thanks!

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 14, 2021

@max-radin thanks for the PR! This LGTM, merging. @NilsNemitz thanks for reviewing!

@j9ac9k j9ac9k merged commit 434c31e into pyqtgraph:master Nov 14, 2021
ntjess pushed a commit to ntjess/pyqtgraph that referenced this pull request Dec 10, 2021
* Updating pytest command in CONTRIBUTING.md

* Separating x and y flags in AxisItem.setLog; fixes pyqtgraph#997

* Updated AxisItem.setLogMode to be backwards compatible
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 this pull request may close these issues.

Adding an AxisItem to a PlotItem causes an exception

3 participants