How to make graph multiple colors?

1 visualizzazione (ultimi 30 giorni)
Wesley
Wesley il 17 Gen 2013
I have a graph in matlab that is a line. The data ranges from 0 to 1000. I want to make the data at 0 to be one color and for all the other data to be another color. How do I do this?
Thanks
  1 Commento
Jing
Jing il 17 Gen 2013
I'm not sure whether there's way to achieve this in a single line. But you can get the same appearance with multiple lines.

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 17 Gen 2013
Data are just points. Lines go in between the points. What is "data"? Is it your "y" values, or your x values? Let's say
x = [0,2,4,5,6,8];
y = [1,0,3,3,0,9];
Do you want the marker at (x,y) = (0,10) to be color1 and all the other markers to be color2, or do you want the lines coming out both sides of the y=0 points going to the adjacent points be different colors? In other words, the line from (0,1) to (2,0) and the line going from (2,0) to (4,3) etc. I'm not sure if it's the markers at the data locations you want or if it's the lines in between the data locations. I'm not sure what "make the data at 0 to be one color" means, especially after you were talking about lines, not points. Please clarify. Either way you can use two plot() calls.
  4 Commenti
Walter Roberson
Walter Roberson il 17 Gen 2013
Do you want lines connecting the points, or no lines? If you do not want lines connecting the points, then use scatter() as that allows you to adjust the colors on a point-by-point basis. If you do want lines connecting the points, then you need to tell us what color to use for the line connecting points of different color.
Wesley
Wesley il 17 Gen 2013
For this data, I was given a table full of data points. I graphed the data by using plot(x,y). I then made the color black by doing plot(x,y,'--*k'). I want all the points to be black except for the point at 0, which I want to be red. I did not use scatter(). I'm not sure if plot(x,y) gives you points or lines.

Accedi per commentare.

Categorie

Scopri di più su Discrete Data 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!

Translated by