Plot different colors while using loops.
古いコメントを表示
I am making a program that plots a variable amount of inputs from a database. Suffice to say that I have a variable number of arrays that I need to plot on the same figure. I can get the variables to plot fine with a loop.
for i=1:n
plot(array1(:,i),array2(:,i),'o')
end
This plots i arrays where array1 holds the x values and array 2 holds the y values.
I was wondering if:
a: There is a way to change the colors, in other words, make each dataset show up with different colors.
b: make a legend that coorsponds to the colors. I would like to see which data goes with which plot. I can pull the names from an array...I mainly need some way to color the different plots differently.
4 件のコメント
Ryan Rizzo
2018 年 4 月 16 日
@midhun, grazzi. This worked. Thanks
Karam Haidar
2020 年 5 月 23 日
does this literally only work with the numbers 1 and 3? I had a similar problem and it spit out an error with every other combination I tried!
Stephen23
2020 年 5 月 23 日
"does this literally only work with the numbers 1 and 3?"
Yes, because RGB triples are defined as a vector of three values.
"I had a similar problem and it spit out an error with every other combination I tried!"
The documentation clearly explains what the valid inputs are for the 'color' option:
Reading the documentation is a much more efficient way to write code than just trying random changes.
採用された回答
その他の回答 (1 件)
Oleg Komarov
2011 年 5 月 31 日
you can simply, and it will automatically change the colors for each series:
plot(array1,array2,'o')
カテゴリ
ヘルプ センター および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!