Multiple line plots of matrix with color depending on other vector
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I am pretty inexperienced with matlab, so sorry if I cannot express myself clearly.
I have a matrix A = 78x31 and I want to make a line plot of the rows, so 78 lines in total.
Additionally I want the range of the line colors to be dependent on the values of a vector B = 78x1.
So for example:
for row 1: B(1) -> 3.3 -> medium color
for row 2: B(2) -> 5.5 -> dark color
for row 3: B(3) -> 2.5 -> bright color etc..
I used the plot(A) before, which works fine, but gives me very random colors. scatter(A,B) does not do the job either.
Thank you in advance!
0 个评论
回答(1 个)
Ameer Hamza
2018-6-26
The order of plot colors is decided by the ColorOrder property of the axes object. You can access this property as
ax = gca;
ax.ColorOrder
for R2014a and older
ax = gca;
get(ax, 'ColorOrder')
So if you have a colorMatrix corresponding to B vales i.e. [78 x 3] matrix, each row is an RGB color. i.e. B(1) = 3.3 -> [r g b]??? is the first row. You need to have RGB values corresponding to each value in B. Then you can use the colorMatrix to change the value of ColorOrder property.
ax.ColorOrder = colorMatrix;
For older versions
set(ax, 'ColorOrder', colorMatrix);
So the main task here is to generate such a colorMatrix based on values in vector B. Although it is possible to get such a colorMatrix using colormap() function, it is difficult to suggest an exact solution unless you can provide with a sample dataset.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!