Traceback (most recent call last):
File "/home/vieler/issue.py", line 8, in <module>
p1.addItem(ax2)
File "/home/vieler/.virtualenvs/general/lib/python3.7/site-packages/pyqtgraph/graphicsItems/PlotItem/PlotItem.py", line 526, in addItem
item.setLogMode(self.ctrl.logXCheck.isChecked(), self.ctrl.logYCheck.isChecked())
TypeError: setLogMode() takes 2 positional arguments but 3 were given
Tested environment(s)
PyQtGraph version: 0.10.0
Qt Python binding: PyQt5 5.12.1 Qt 5.12.2
Python version: 3.7.3
NumPy version: 1.16.4
Operating system: Arch Linux x64
Installation method: pip
Ran this through the debugger, this is really weird, put the breakpoint right before the call, verified I'm getting booleans from the self.ctrl.log[X|Y]Check.isChecked()
but it's still saying it's getting 3 positional arguments.
Then I called it myself with
(Pdb) item.setLogMode(False, False)
*** TypeError: setLogMode() takes 2 positional arguments but 3 were given
As soon as I typed that issue, I figured out the problem
AxisItem.setLogMode
takes in arguments of self
and log
, whereas PlotItem.setLogMode
, takes arguments of self
, x
and y
.
Fix likely would involve making setLogMode
for axisItem take the same arguments as PlotItem...but changes in the rest of the code base will likely need to take place to make sure things are compatible.
I'm curious about use cases for adding additional AxisItem
s to a PlotItem
's ViewBox
. The PlotItem
is basically a grid layout with four AxisItem
objects bounding a central ViewBox
, so there are already top and right AxisItem
s which you can show with e.g. plotItem.showAxis('right')
. Also see examples/MultiplePlotAxes.py for an approach to making plots with separate left/right axes.
Though I suppose just from an API standpoint it makes sense to be able to add any of the *Item
objects to a plot without raising an exception. The simplest thing to do is just add and not isinstance(item, AxisItem)
here:
pyqtgraph/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
Lines 498 to 499
ad7453c
First, I didn't really know that the right AxisItem was already there, but hidden. I thought that the layout could accommodate one but you had to create it yourself (well, my fault 😃 ).
Second, I still think that there are two reason to fix this problem:
In the docs, it says
Use addItem() to add any QGraphicsItem to the view.
So either this documentation part gets corrected or the code is.
@ixjlyons rightly asks for a use case. I agree that it might be a bit specific but, for example, you would want to display the same data in two different ways. The simplest example I can think of is showing the "lossess" of system (an optical component, a transmission line...) in both dB and %. Or even, in spectroscopy, you might want to display your X axis in both nanometers and cm-1
* Updating pytest command in CONTRIBUTING.md
* Separating x and y flags in AxisItem.setLog; fixes #997
* Updated AxisItem.setLogMode to be backwards compatible
* Updating pytest command in CONTRIBUTING.md
* Separating x and y flags in AxisItem.setLog; fixes pyqtgraph#997
* Updated AxisItem.setLogMode to be backwards compatible