How to add different colors to one line chart
Mostra commenti meno recenti
I have a line plot, and i need it to change colour depending on some criteria.
I have the chart below, adn i want this charge to have different colors at different areas.
I've shown two charts below.
I want to change the colors of the top chart, depending on where the bottom chart is.
For eg. if the bottom chart is near 0, then show blue, if the bottom chart is up near 500 make the color of the top chart red, if the bottom chart is down near -500, then make the color of the top chart green.
All the documentation i've seen is about adding new lines with different colors, i don't want that, i want one line with multiple colors.
If someone can assist, that would be great.


1 Commento
Here are two demos that produce what appears to be a single line with varying color.
If you want to get into undocumented methods,
But one of the functions Walter Roberson mentioned is probably the easiest route for your task.
Risposta accettata
Più risposte (1)
Walter Roberson
il 14 Set 2020
0 voti
It is not possible in MATLAB for one Chart Line Object to have multiple colors.
For multiple colors you have a few possibilities:
- multiple line objects
- create a surface() with careful control over node colors and edge coloring configuration.
- create a patch() with careful control over node colors and edge coloring configuration.
4 Commenti
Rizwan Khan
il 15 Set 2020
Rizwan Khan
il 15 Set 2020
Walter Roberson
il 15 Set 2020
You can use zero for the z.
So if i want to make a chart like below, its not possible?
It is not possible with a single Chart Line Object (more commonly known as a line() object.)
The underlying graphics system (OpenGL) that transforms coordinates into graphics, just does not support drawing multicolored lines as one of its "primitive" operations.
There are other ways to draw graphs like the one you picture -- but those ways do not involve using a single Chart Line Object.
Walter Roberson
il 15 Set 2020
Using the first of the links I gave, color_line3:
color_line3(days, stock_price, zeros(size(stock_price)), detrended_stuff)
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




