silx-kit / silx

silx toolkit
http://www.silx.org/doc/silx/latest/
MIT License
119 stars 70 forks source link

addCurve advances color index even if color is provided #4133

Closed EdgarGF93 closed 2 weeks ago

EdgarGF93 commented 3 weeks ago
from silx.gui.plot import Plot2D
import numpy as np
from PyQt5.QtWidgets import QApplication, QMainWindow

if __name__ == "__main__":
    app = QApplication([])
    mw = QMainWindow()
    plot = Plot2D()

    x = np.linspace(0,10,10)
    y = [x, x ** 2]

    for _ in range(2):
        color, style = plot._getColorAndStyle()
        #color = f"black"
        print(f"color index is {plot._colorIndex}")
        plot.addCurve(x,y[_], color=color, legend=_)

    mw.setCentralWidget(plot)
    mw.show()
    app.exec_()
color index is 1
color index is 3

Would it make sense to make an if statement here? If the color is provided (custom color or because we have requested the color before), do not request a new color

https://github.com/silx-kit/silx/blob/755fa6d3cbe35e1078f65557f6e9e8352b826da5/src/silx/gui/plot/PlotWidget.py#L1203C1-L1203C72

t20100 commented 3 weeks ago

Yes definitely! It would also need to be fixed in PlotWidget.addHistogram

EdgarGF93 commented 3 weeks ago

To #4138

t20100 commented 2 weeks ago

Reopening, this will get closed when PR #4138 gets merged