Closed EdgarGF93 closed 2 weeks ago
Thanks for the PR!
I think the rotation of the color and style should be handled differently between the 3 cases:
This code
from silx import sx
w = sx.plot()
w.addCurve([1, 2], [0, 1], legend="1")
w.addCurve([1, 2], [0, 2], legend="2")
w.addCurve([1, 2], [0, 3], legend="3", color="black")
w.addCurve([1, 2], [0, 4], legend="4")
displays:
So passing only the color rotate the linestyle.
I would propose the following behavior:
-
linestyle all the time or eventually rotate linestyle but independently from the other casesblack
) to have a similar behavior as the "only color" case with always the same linestyle, but as a user I would expect the colors to rotate...What do you think?
Also, we need to keep the behavior as compatible as possible in order to limit unexpected changes for application using it.
The way I did it:
I think this is the logical way, if the user provides a constant color and style, (s)he is aware that eventually the color-style is going to be duplicated. Is this behavior something to avoid at all? Because in that case we can easily use only one method (_getColorAndStyle), both indices (color and style) are always connected, and then repetition of curves is always avoided. I'm voting for keeping the frozen color-style (there has be to a situation in which the user would want to freeze the style)
if the user provides a constant color and style, (s)he is aware that eventually the color-style is going to be duplicated.
Agreed.
To me the key issue is that if both color and style are provided, it should not rotate the default. Now when changing this, we have to keep an eye on providing a similar behavior for backward compatibility at the same time as improving this behavior.
The fact that adding a curve with a color rotates the style for the next curve without color (see code in https://github.com/silx-kit/silx/pull/4138#issuecomment-2176415182) sounds hard to understand without knowing the internals, thus my previous propositions reorganised here:
- If no color and style is provided, rotate both with the same method (_getColorAndStyle) as before
- If both are provided, it uses it but it does not request them again (that was the reason I opened the issue).
Agreed. Regarding the remaining cases:
If color provided: If the styles rotates there, it should not interfere with the " no color and style is provided". I'm in favor of always using a solid line style here, because rotating the style would mean keeping a record of which style was last used for which color (not worth it IMO).
If style is provided, it rotates the color. After 10 curves, it takes the same color-style OK for me, and I would use _getColorAndStyle @axelboc suggested using the previously used default color (i.e. take the color but do not rotate) unless the current default style is the same, and in this case do a rotation.
Anyone has comments on this discussion?
Ok, yes, I fully agree with not-rotating the style if color is provided, especially because is keeping the same behavior as before the PR
I think this way it stays as similar as before but solving the index bug and the rotating style discussion
perfect, thanks
Checklist:
<Module or Topic>: <Action> <Summary>
(see contributing guidelines)From #4133
This PR fixed the way the addCurve requests color and style (examples) Test code:
Before the PR, addCurve request the color again (not to be used) but advances +1, so the colormap finish after 5 iterations:![image](https://github.com/silx-kit/silx/assets/112327909/3454edf9-7d91-49a7-8705-b3100db96ee9)
Before the PR, it waits 10 color indexes to change the style:![image](https://github.com/silx-kit/silx/assets/112327909/b2629711-d1b8-461f-b1f1-d7b3472437c9)
closes #4133