Colormap by variable using plot function
Ältere Kommentare anzeigen
Hello!
I am plotting data from a three-column table: x-value, y-value and cycleNumber. I would like to make a plot of y-value vs. x-value, but assign a different color from a colormap to each group of rows with the same cycle number.
I found how to do this using the scatter function:
s1 = scatter(table,'x-value','y-value','filled','ColorVariable','cycleNumber');
but I would prefer an output that the typical plot function gives. Is it possible to assign a 'ColorVariable' to the plot function?
Here is what my data look like right now. Not bad, but I wish the points were connected.

3 Kommentare
Rik
am 7 Jul. 2022
Have you read the documentation for the plot function? If so, what have you tried?
Rik
am 7 Jul. 2022
That is indeed the way I would go. Remember that higher level functions provide easier tools, at the cost of flexibility.
But there may be another way: Mathworks engineers have probably done the exact same thing I'm suggesting you do. So they probably call plot (or the line primitive) somewhere in their code. This means you can query the Children properties of the axes (or the object returned by the scatter function) and you will probably eventually find line objects. When you do, you can edit the LineStyle properties to match what you need.
Not quite 1 line of code, but once you find the correct call, you should be left with 1 or 2 lines.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Scatter Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

