-
-
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
Grid supports anti-aliasing #2864
base: master
Are you sure you want to change the base?
Conversation
…consistent width when drawing.
Hi @Asachoo thanks for the PR The diff looks good to me, is there a reason that you think that the grid should have anti-aliasing disabled by default? I know there is a performance penalty, but I'm wondering if this is a use-case where it might be worthwhile.... Do you have a hidpi monitor, and if so, do you know what scaling factor you are using? I wonder if this is one of those things where if you had non-integer based scaling vs. integer based scaling... |
@j9ac9k Hi, thank you for reviewing the PR. Regarding the first point, I actually introduced an optional parameter based on the existing default settings. In other words, setting anti-aliasing to False is the default option for this PR. After conducting a quick investigation, it seems that this default configuration has been in place for the past 12 years. Considering the longstanding acceptance of this option, I decided not to change the default configuration of disabling anti-aliasing. However, personally, I would prefer to have anti-aliasing enabled by default as I have found the performance impact to be minimal in my experience. Regarding your second point, on my Windows laptop with a resolution of 1920*1080, the scaling factors of 100%, 125%, and 150% provide a consistent experience. However, I am unsure how it would perform on higher-resolution displays. Please let me know if there's anything else or if further improvements are needed. |
Hi @Asachoo Thanks for your detailed response, I appreciate the effort to preserve existing behavior. I think in this case, we should change the default You can see an example of it being used here: pyqtgraph/pyqtgraph/examples/PlotSpeedTest.py Line 121 in fa26ece
|
A quick comment on why this is off by default and doesn't use the library anti-alias setting so far: I believe I have seen the library code turn off anti-aliasing in multiple places for lines that are perfectly vertical or horizontal. My interpretation has been that this exactly tries to avoid the problem shown in @Asachoo 's demonstration images: With anti-aliasing on, a fractional position would draw over two pixel coordinates at reduced intensity. Turning anti-aliasing off for these lines is (I believe) supposed to make sure they always draw aligned with one particular row or column of screen pixels. Effectively this used to trade a sub-pixel position error for a sharp and consistent appearance. The demo images show that this does not seem to work in all cases anymore. Fractional scaling modes of 125% and 150% would be an obvious reason. If it even breaks in 100% mode now, then its clearly time to remove the special treatment of vertical and horizontal lines. But if it still works in non-scaled modes, then it might be good to keep the special status for now (until the majority of users have screens with more pixels than the eye can resolve). Maybe a new config option for antialiasing the grid-aligned horizontal / vertical lines might be an option for a smooth transition? I expect that we'll start seeing this problem in multiple places. |
Can you share the code you used to generate the screenshots? I have access to hidpi/non-hidpi displays on both macOS and Windows (and could do Linux if needed too). I agree with @NilsNemitz that historically we've disabled anti-aliasing on vertical or horizontal lines for the reasons he stated, but if we're getting the behavior you're seeing across platforms; we clearly need to revisit the assumption that disabling anti-aliasing will make vertical and horizontal lines sharp/consistent. |
As an example, #2709 disabled anti-aliasing for horizontal and vertical infinite lines. I think perhaps the issue may have to do with the combination of opacity + anti-aliasing + hidpi? I did see some strangeness with the Auto button which changes its opacity whenever the mouse hovers over it. |
I apologize for not submitting my test case code at the beginning. My test case has been tested on both Windows and Ubuntu. The pyqtgraph plotting is not directly performed in QMainWindow, but rather in a QMdiSubWindow created within QMdiArea (this information might be important, and I apologize for not mentioning it initially). Here is the extracted test code based on my project, which has been tested and can reproduce the issue on my machine (system, screen and packages summary: Ubuntu 22.04.3 LTS, resolution 1560*1440, scale 100%, PySide2 5.15.2.1, pyqtgraph 0.13.3).
The screenshot of the plot result shows that the grid lines have inconsistent and irregular widths |
I have stripped down your example. The relevant point seems to be that you have chosen a non integer-sized pen width. import pyqtgraph as pg
pg.mkQApp()
pw = pg.PlotWidget()
pw.showGrid(True, True)
width = 1.75 # culprit
axis_pen = pg.mkPen(color="w", width=width)
for orientation in ("bottom", "left"):
pw.getAxis(orientation).setPen(axis_pen)
pw.show()
pg.exec() |
Wonder if we should have a helper method to check if we should use anti-aliasing or not, based on whether we have a non-integer pen thickness or if the lines are horizontal/vertical. Also wonder if InfiniteLine line would suffer from the same issue... |
Sorry for the long delay here. I moved cross country and had to pack up my computers and some of my laptops, so I have been unable to test this in a way that's needed. I need to investigate which platforms (macOS/windows/linux) and which combination of hidpi/non-hidpi screens as well. Anyway I'm getting setup where I'm temporarily residing so I should hopefully be able to start testing this more thoroughly in the near term. |
The grid created using the showGrid method will invoke the setGrid method of Axis to configure various properties of the grid. However, due to the default setting of anti-aliasing to False in the drawPicture method of Axisitem.py, the resulting grid often appears to have inconsistent thickness (even though the line width of QPen remains consistent).
pyqtgraph/pyqtgraph/graphicsItems/AxisItem.py
Lines 1238 to 1249 in cdb177c
In this PR, i have added a new property in the setStyle method to allow users to determine whether to enable anti-aliasing rendering for grid objects.
The following two pictures show the difference between whether the axis is set to anti-aliasing or not.
without anti-aliasing:
with anti-aliasing:
After adding the anti-aliasing attribute, the entire grid does look clearer and neater.
Other Tasks
Bump Dependency Versions
Files that need updates
Confirm the following files have been either updated or there has been a determination that no update is needed.
README.md
setup.py
tox.ini
.github/workflows/main.yml
and associatedrequirements.txt
and condaenvironemt.yml
filespyproject.toml
binder/requirements.txt
Pre-Release Checklist
Pre Release Checklist
__init__.py
CHANGELOG
primarily using contents from automated changelog generation in GitHub release pagePost-Release Checklist
Steps To Complete
.dev0
to__version__
in__init__.py