![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284362/image.png)
Setting line colour between two matrix plots on the same graph
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
William Gray
il 14 Apr 2020
Commentato: William Gray
il 17 Apr 2020
Hi everyone, so I'm sure there is a simple answer to this but I can't quite figure it out. Say I have two 4x4 matracies, X and Y that I want to plot on the same graph against the same variable Z, I am currently doing something like this:
plot (X,Z,'.')
hold on
plot (Y,Z,'*')
title ({title})
legend ('X','Y')
I am wanting the colour of the plots X and Y to match up for different Z values. So for example, X(:,1) and Y(:,1) are both red, X(:,2) and Y(:,2) both green etc...
I hope that explenation makes sense, any help would be very much appreciated. I know I could use a for loop to just plot the columns individually and then set the colour but I thought there may be a much quicker way?
Thanks,
Will
0 Commenti
Risposta accettata
Ameer Hamza
il 14 Apr 2020
Modificato: Ameer Hamza
il 14 Apr 2020
You just need to reset the color order index every time you start the colors from the beginning
X = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4]';
Y = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4]'+4;
Z = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4]'+(1:4);
ax = axes();
plot (X,Z,'.')
hold on
ax.ColorOrderIndex = 1; % <--- reset the ColorOrderIndex to 1
plot (Y,Z,'*')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284362/image.png)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!