-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
showGrid screws up tick labels at axis boundaries #1606
Comments
I have this issue too. Thanks for pointing out the relationship with the grid. It helped me find the root cause. In line 567 of graphicsItems/AxisItem.py following code is in place:
This function extends the rectange of the axis beyond the viewbox , but only if self.grid is False. I am not sure what the purpose of this behavior is. Perhaps anyone of the developers can have a look. Edit:I just discovered that this change breaks the grid when zooming in the plot. The grid lines are sometimes not showing up, or just partly showing up. |
I also am having this issue. After some experimentation, I changed the method boundingRect in graphicsItems/AxisItem.py as follows: def boundingRect(self):
linkedView = self.linkedView()
if linkedView is None or self.grid is False:
rect = self.mapRectFromParent(self.geometry())
else:
rect = self.mapRectFromParent(self.geometry()) | linkedView.mapRectToItem(self, linkedView.boundingRect())
## extend rect if ticks go in negative direction
## also extend to account for text that flows past the edges
tl = self.style['tickLength']
if self.orientation == 'left':
rect = rect.adjusted(0, -15, -min(0,tl), 15)
elif self.orientation == 'right':
rect = rect.adjusted(min(0,tl), -15, 0, 15)
elif self.orientation == 'top':
rect = rect.adjusted(-15, 0, 15, -min(0,tl))
elif self.orientation == 'bottom':
rect = rect.adjusted(-15, min(0,tl), 15, 0)
return rect That seems to correct the problem. However, I am not sure, if this change causes problems elsewhere ... |
swvanbuuren's suggestion is a great improvement. The issue is avoided by not extending the y-axis upwards if self.orientation == 'left':
rect = rect.adjusted(0, -15, -min(0,tl), 0) |
By undoing the extension of the y-axis upwards, the original issue resurfaces when panning in vertical direction. The problem is caused, due to the fact that grid lines are part of an AxisItem (i.e. vertical grid lines are part of a horizontal axis and vice versa). If grid lines are not present, extending a particular axis does not interfere with the other axes, since the bounding box (defined in boundingRect) fits neatly around the axis labels and ticks and does not get in the way of other axes. However, when grid lines are present, the bounding box also includes the whole plot area (due to the grid lines) and extending this causes overlaps with other axes. In the end, I think the best solution would be, to have a separate Item (that derives from GraphicsWidget, e.g. named GridItem) for the grid lines. |
We do have a GridItem and I agree we should probably move toward that for providing a grid because the current situation with AxisItems causes a number of problems. |
FYI I Just noticed that GridItem does not work with a log-scaled axis. |
another one for the list! log-scale |
I tested with GridItem instead of the built-in grid of AxisItem and this seems to overcome this current issue. However, there's a problem with GridItem: Wouldn't it be better if AxisItem and GridItem used the same method (in e.g. a TickItem or similar?) for calculating tick and grid line positions? |
Any chance to have an official fix in a next release ? |
Short description
When I use showGrid (current master and 0.11.1), then the tick labels at the corner of the axes rectangle are not drawn correctly.
Code to reproduce
Actual and Expected behavior
This is the output of the above script:
Tested environment(s)
The text was updated successfully, but these errors were encountered: