How Does SeriesIndex Work with LineStyleOrder?

5 visualizzazioni (ultimi 30 giorni)
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')
ans = 3x1 cell array
{'--x'} {'--o'} {'--*'}
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')
ans = '-'
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
ans = 3x1 cell array
{'--x'} {'--o'} {'--*'}
Note: the line is '--x' because the default for LineCyclingMethod is 'aftercolor' (I think)
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 Commenti
Paul
Paul il 1 Set 2024
Yes, you are correct. If NextPlot is set to 'replace', then adding a new plot to the axes will
"Delete existing plots and reset axes properties, except Position and Units, to their default values before displaying the new plot."
So I guess everything is working as documented, even if the doc could be much more clear about this in the LineStyleOrder section.
dpb
dpb il 1 Set 2024
Modificato: dpb il 1 Set 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".

Accedi per commentare.

Risposta accettata

Sandeep Mishra
Sandeep Mishra il 2 Set 2024
Hi Paul,
I ran the provided code snippet and observed the similar results.
I found a way to set the LineStyleOrder property of the axes without using the hold function to get the desired result. You can set the property using the following code snippet:
% Setting LineStyleOrder property for 'ax' axis
ax.LineStyleOrder = linestyleorder({'--x','--o','--*'});
This method should allow you to set the LineStyleOrderof the axes and achieve the expected result.
Please refer to the below documentation for more information on linestyleorder property: https://www.mathworks.com/help/releases/R2024a/matlab/ref/linestyleorder.html
I hope this helps!
  3 Commenti
Paul
Paul il 2 Set 2024
Thanks for finding this new function linestyleorder that was added in 2024a.
Just want to point out that linestyleorder can be used just like xlim (for example) in that there is no need to explictly assign its output to the axis property. It automagically sets the LineStyleOrder of all of the axes in the current figure (or one can specify a specific target as a first argument).
figure
hAx=axes;
linestyleorder({'--x','--o','--*'});
plot(rand(4,1))
hAx.LineStyleOrder
ans = 3x1 cell array
{'--x'} {'--o'} {'--*'}
At first I was confused by the statement on the doc page "linestyleorder(linestyles) sets the line style order for the current figure." insofar as LineStyleOrder is a property of an axis. Then I realized it probably meant to refer to the children of the current figure, and it should also say "sets the default line style order for the current figure." (see discussion below).
figure
hax1 = subplot(211);
hax2 = subplot(212);
linestyleorder({'--x','--o','--*'});
plot(hax1,rand(4,1))
plot(hax2,rand(4,1))
linestyleorder is an ordinary m-file (and not very long) so I took a look to see why it works differently and makes the LineStyleOrder "stick" when NextPlot == 'replace'. It looks like (and I could be wrong) that if the target input is not specified (or presumably specified as a figure), then linestyleorder sets the DefaultLineStyleOrder at the figure level (in addition to setting the LineStyleOrder of any applicable children that currently exist in the figure). I think it's the Default property at the figure level that makes the behavior "sticky" and operate across all subplot axee as shown above.
However, we don't get "stickiness" if we explicitly specify an axis as the target.
figure
hAx=axes;
linestyleorder(hAx,{'--x','--o','--*'});
plot(rand(4,1))
hAx.LineStyleOrder
ans = '-'
So I guess this case is equivalent to where this all started, i.e.,
%hAx.LineStyleOrder = {'--x','--o','--*'};
dpb
dpb il 2 Set 2024
Modificato: dpb il 2 Set 2024
@Paul, thanks for the additional input/testing/spelunking. For various reasons, I'm still using R2021b here and haven't taken the time to install a later version (given the slow bandwidth of connections in rural America, it takes in the hours time frame any more with the explosion in size and with no automagic restart, it's a far thing from certain it will complete the first time).

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by