Skip to content
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

Curve fillLevel behaviour with enableExperimental #2878

Open
dmax366 opened this issue Nov 12, 2023 · 4 comments
Open

Curve fillLevel behaviour with enableExperimental #2878

dmax366 opened this issue Nov 12, 2023 · 4 comments

Comments

@dmax366
Copy link

dmax366 commented Nov 12, 2023

Short description

Are fill levels for PlotDataItems supposed to be supported while useOpenGL and enableExperimental are True?
A comment in another issue (#2257) mentions that fill levels are not supported while enableExperimental is False, but I observe the opposite.
Also, why does fill level support depend on enableExperimental, but FillBetweenItem objects are able to display whether enableExperimental is true or false?

Code to reproduce

The code below generates one curve with the fillLevel set and a FillBetweenItem using a different curve, so the two behaviours can be compared.
There is a button to toggle enableExperimental.

import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets

import numpy as np

pg.setConfigOptions(useOpenGL = True, enableExperimental = False)

app = pg.mkQApp('OpenGL / Experimental Test')
win = pg.GraphicsLayoutWidget(show = True, title = 'OpenGL / Experimental Test')

plot = win.addPlot(title = 'Sinusoidal')
x_data = np.linspace(-10, 10, 1000)
curve = plot.plot(x_data, np.sin(x_data), pen = 'green', fillLevel = 0, fillBrush = pg.mkBrush((150, 0, 200, 100)), name = 'Sinusoidal')
y_data = np.sin(x_data*2.0)
curve2 = plot.plot(x_data, y_data, pen = 'red', name = 'Sinusoidal 2')

filler = pg.FillBetweenItem(curve, curve2, brush = pg.mkBrush((200, 200, 0, 100)), pen = 'pink')
plot.addItem(filler)

button = QtWidgets.QPushButton('enableExperimental = False')
en_exp = False
def toggle_experimental():
    global en_exp, button
    en_exp = not en_exp
    pg.setConfigOptions(enableExperimental = en_exp)
    button.setText(f'enableExperimental = {en_exp}')

button.clicked.connect(toggle_experimental)
proxy = QtWidgets.QGraphicsProxyWidget()
proxy.setWidget(button)

win.addItem(plot, 0, 0)
win.addItem(proxy, 1, 0)

win.show()
pg.exec()

Expected behavior

The curve with fillLevel set should be filled while enableExperimental = True.

Real behavior

The curve with fillLevel set is not filled while enableExperimental = True. Instead, it is filled while enableExperimental = False.

Tested environment(s)

  • PyQtGraph version: 0.13.3
  • Qt Python binding: PyQt6 6.5.3 Qt 6.5.3
  • Python version: 3.11.1
  • NumPy version: 1.24.3
  • Operating system: Windows 10
  • Installation method: pip
@pijyoi
Copy link
Contributor

pijyoi commented Nov 12, 2023

A comment in another issue (#2257) mentions that fill levels are not supported while enableExperimental is False, but I observe the opposite.

The comment in question:
enableExperimental=False (indeed, fill level is not implemented in this codepath)

What was meant: that it was a good thing that enableExperimental was set to False, because fill level was not implemented for useOpenGL=True and enableExperimental=True

Also, why does fill level support depend on enableExperimental, but FillBetweenItem objects are able to display whether enableExperimental is true or false?

useOpenGL=True causes Qt to use OpenGL as a rendering backend for the QGraphics system. This is supposed to work transparently and no other changes are needed for pyqtgraph library code.

In addition, enableExperimental=True causes pg.PlotCurveItem to switch to drawing lines using native OpenGL commands.
pg.PlotCurveItem is the only GraphicsObject that is affected by enableExperimental=True.

How fill level is implemented:
When fill level is enabled, the pyqtgraph library joins the ends of the plot curve together such that there is an enclosed polygon. It then requests the Qt library to flood fill the enclosed polygon.
FillBetweenItem is implemented in the same way.
As long as only Qt painting commands are used, it works whether or not OpenGL is used as a rendering backend.

Expected behavior
The curve with fillLevel set should be filled while enableExperimental = True.

When enableExperimental=True, native OpenGL commands are used for pg.PlotCurveItem and no flood-filling functionality is implemented.

@dmax366
Copy link
Author

dmax366 commented Nov 12, 2023

Thank you for the clarification @pijyoi. Apologies for misreading your comment.
So if we need to fill curves while useOpenGL and enableExperimental are true, is FillBetweenItems with a "fill level" curve the recommended workaround?

@pijyoi
Copy link
Contributor

pijyoi commented Nov 12, 2023

So if we need to fill curves while useOpenGL and enableExperimental are true, is FillBetweenItems with a "fill level" curve the recommended workaround?

Well, my recommendation is to not use the native OpenGL painting mode of pg.PlotCurveItem. i.e. don't use useOpenGL=True and enableExperimental=True.

Personally, I don't use enableOpenGL=True at all, the library performance is good enough as is for my use.

@dmax366
Copy link
Author

dmax366 commented Nov 13, 2023

Understood. Thank you for taking the time to respond.
After some further testing, I've concluded that my application works best with useOpenGL = False and that enableExperimental doesn't noticeably impact UI responsiveness. At least for my use case.
It was more beneficial to put in the option to turn off curve fill to improve UI responsiveness when the curve contains a lot of points.

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

No branches or pull requests

2 participants