How Does SeriesIndex Work with LineStyleOrder?
Show older comments
My interpretation of SeriesIndex is that it controls the color and style of a line based on the ColorOrder and the LineStyleOrder properties of the axes.
figure;
ax = gca;
ax.LineStyleOrder = {'--x','--o','--*'};
get(gca,'LineStyleOrder')
plot(1:3,1:3,SeriesIndex=2),axis padded
I did not expect the line to be solid without a marker.
The LineStyleOrder has changed back to the default?
get(gca,'LineStyleOrder')
It turns out that "hold" must be called after setting the LineStyleOrder and before the plot
figure;
ax = gca;
ax.LineStyleOrder = {'--x','--o','--*'};
hold on
plot(1:3,1:3,SeriesIndex=2),axis padded
ax.LineStyleOrder
However, according to LineStyleOrder the need to call 'hold' prior to plot() should only apply for releases prior to 2019b.
Is the doc in error or am I misreading it?
5 Comments
I dunno for certain, but the note says "when you continue to plot in the axes" which to me implies that hold on must already be in place or the content of the axes will be reset.
If we try
hAx=axes;
hAx.NextPlot
hAx.LineStyleOrder = {'--x','--o','--*'};
hAx.NextPlot
we find that setting the LineStyleOrder does not change the state of .NextPlot I'm not sure the note applies or how else it would work without messing up what hold means royally and break a zillion working pieces of code.
I dunno what would happen (well, actually, I think I do have a pretty good guess <g>) if we tried
figure;
hAx=axes;
hAx.LineStyleOrder = {'--x','--o','--*'};
hAx.LineStyleOrderIndex=2;
plot(1:3,1:3)
Well, the color index was incremented but the line style still reverted to default...I'd say things there are still not working quite as may be intended.
I'll admit I've never tried to mess with the cycling order stuff other than specifically setting individual line properties via the lookup kind of thing of the other thread regarding markers...it's just too messy to fool with imo.
Paul
on 1 Sep 2024
But note in particular the "... MATLAB updates the styles of any lines that are in the axes. If you continue plotting into the axes, your plotting commands continue ..."
If 'NextPlot' is still 'replace', then there aren't going to be any lines to continue from, however. This is basically what your experiments have shown.
figure
plot(rand(3))
plot(rand(4))
plots iInto the same axes, yes, but with a big difference in behavior depending upon the state of 'NextPlot'.
My reading (and what is borne out by experiment) is that setting the order manually doesn't "stick" unless are already adding to the same axes, not replacing its content.
Now, as my comments went on to say, I can believe the observed behavior may not be exactly what MATHWORKS has intended, but it's such a messy, murky area, I doubt there is a truly clean solution with existing HG2 structure; too much is too intertwined.
I think unless one spends an inordinate amount of time digging into it, the only way to guarantee what you're going to get will be to take the old way out -- set the linestyle triad and order explicitly on the already existing lines or create them with the desired triad in the first place.
Paul
on 1 Sep 2024
I don't disagree about the doc with that new(ish at least) section regarding the order; it reads as if the writer of the documentation (who undoubtedly was not the developer) did expect the revised line order to begin with the value set, not connecting the behavior of HG2 with respect to what the 'NextPlot' property does.
Only that I knew already that unless 'NextPlot' is not 'replace' the axes properties are reset such that could check that setting the 'LineStyleOrder' did not also change its state was I able to infer that "continue" in that context had to imply that hold on had to have been executed in order to effect the described behavior with respect to continuation of the numbering sequence/style and that even if you were to change existing lines by the order vector index, unless hold on were set a new line would still reset the axes, wiping out the existing lines. From that I inferred the "continue" had to be in conjunction or the described behavior would not occur.
I wonder if, indeed, the intention with whatever was, specifically, changed in R2019b isn't actually implemented as what was intended or the explanation is just murky/garbled in not actually describing what the intended behavior is supposed to be.
It is probably worth a bug/support request asking for both clarification in intent/documentation if behavior is as intended or as a bug if it is really supposed to reset the order and not revert back to default when user does set an order vector -- or that it is, indeed, implied/required for the user to call hold on if wants the changed order to "stick".
Accepted Answer
More Answers (0)
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






