By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here.

Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I'm trying to color code text in a legend. Since I'm trying to sort several plots into different categories, I can't just rely on the line colors in the legend.

I've managed to set the text color for the entire legend, but I can't manage to assign it line by line. Is this possible? I'd like to be able to make some red, and some black. I also poked around the legend properties using get legbut I couldn't find anything else that seemed useful.

Any suggestions? While the answers by yuk and gnovice are correct, I would like to point out a little-known and yet minescape software fact that the legend function returns additional handles that correspond to the legend components. From the documentation of the legend function:. To change the legend text colors individually, you have to first get the handles to the text objects, which are children of the legend object.

Then you can change their text colors separately. Here's an example of how you can do it:. Note that the color order in the last line is blue then red, in reverse order of the way the labels are passed to the legend function. The above will give you the following plot:. Learn more. Asked 10 years, 2 months ago. Active 2 years, 9 months ago. Viewed 24k times. Doresoom Doresoom 7, 14 14 gold badges 42 42 silver badges 60 60 bronze badges.

Active Oldest Votes. Georg Fritzsche Yair Altman Yair Altman 5, 27 27 silver badges 34 34 bronze badges. Thanks for pointing that out! I guess I should read the documentation file more closely next time. Good catch, Yair. That'll teach me to completely read the current documentation instead of answering from memory.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.Sign in to comment. Sign in to answer this question.

Unable to complete the action because of changes made to the page. Reload the page to see its updated state. Based on your location, we recommend that you select:.

Select the China site in Chinese or English for best site performance. Other MathWorks country sites are not optimized for visits from your location. Toggle Main Navigation. Recherche Answers Clear Filters. Answers Support MathWorks. Search Support Clear Filters. Support Answers MathWorks. Search MathWorks. MathWorks Answers Support. Open Mobile Search. You are now following this question You will see updates in your activity feed.

You may receive emails, depending on your notification preferences. Multiple legends with colors. Vote 0. Accepted Answer: Image Analyst. Hi, if k is 7, then colors for legends are repeating for each leg. How can I generate different color for each value in plot?

Or it is possible to make for leg1 different colors with -b, for leg2 the same colors like for leg1 but with -ro. This is my code:.

How to set different colors for the text in a legend ?

Please for help. Accepted Answer. Image Analyst on 26 Mar Vote 1. Cancel Copy to Clipboard. See my ColorOrder demo. You can get more colors.Sign in to comment. Sign in to answer this question. Unable to complete the action because of changes made to the page.

Reload the page to see its updated state. Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:. Select the China site in Chinese or English for best site performance.

Other MathWorks country sites are not optimized for visits from your location. Toggle Main Navigation. Search Answers Clear Filters. Answers Support MathWorks. Search Support Clear Filters.

Support Answers MathWorks. Search MathWorks. MathWorks Answers Support. Open Mobile Search. Trial software. You are now following this question You will see updates in your activity feed. You may receive emails, depending on your notification preferences. Editing colors in the legend. Rainer on 8 Jul Vote 0. Commented: Image Analyst on 29 Jan Sign in to comment. Sign in to answer this question.

matlab legend multiple colors

Unable to complete the action because of changes made to the page. Reload the page to see its updated state. Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:. Select the China site in Chinese or English for best site performance.

Other MathWorks country sites are not optimized for visits from your location.

matlab legend multiple colors

Toggle Main Navigation. Search Answers Clear Filters. Answers Support MathWorks. Search Support Clear Filters. Support Answers MathWorks. Search MathWorks. MathWorks Answers Support. Open Mobile Search. Trial software. You are now following this question You will see updates in your activity feed. You may receive emails, depending on your notification preferences.

Vote 4. Commented: Benjamin Schafer on 31 Jan Answers 2. Walter Roberson on 11 Dec Vote 6. Cancel Copy to Clipboard. You can record the handles of the lines, and only pass in one of the red group and one of the blue group to legend.

For example.Documentation Help Center. Legend properties control the appearance and behavior of a Legend object. By changing property values, you can modify certain aspects of the legend. Use dot notation to refer to a particular object and property:. Example: legend 'Location','northeastoutside'. If the legend has multiple columns, layout the items from top to bottom along each column.

matlab legend multiple colors

If the legend has multiple columns, layout the items from left to right along each row. Example: legend 'Orientation','horizontal'. Number of columns, specified as a positive integer. If there are not enough legend items to fill the specified number of columns, then the number of columns that appear might be fewer. Use the Orientation property to control whether the legend items appear in order along each column or along each row.

Example: lgd. Selection mode for the NumColumns value, specified as one of these values:. To specify the value, set the NumColumns property. Custom location and size, specified as a four-element vector of the form [left bottom width height].

The first two values, left and bottomspecify the distance from the lower left corner of the figure to the lower left corner of the legend. The last two values, width and heightspecify the legend dimensions. The Units property determines the position units.

Setting this property has no effect when the parent container is a TiledChartLayout. This property affects the Position property. If you change the units, then it is good practice to return it to its default value after completing your computation to prevent affecting other functions that assume Units is the default value. If you specify the Position and Units properties as Name,Value pairs when creating the object, then the order of specification matters.Sign in to comment.

Sign in to answer this question.

Tutorial - Introducing multiple legends in Matlab figure/ plot

Unable to complete the action because of changes made to the page. Reload the page to see its updated state. Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:. Select the China site in Chinese or English for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Toggle Main Navigation. Search Answers Clear Filters. Answers Support MathWorks. Search Support Clear Filters. Support Answers MathWorks. Search MathWorks. MathWorks Answers Support. Open Mobile Search. Trial software. You are now following this question You will see updates in your activity feed. You may receive emails, depending on your notification preferences. Legend with multiple colors for a single bar plot.

Kenneth on 8 May Vote 0. Commented: Kenneth on 9 May Accepted Answer: Michael Haderlein. I have a single bar plot and i have managed to color the bars in 3 different colors.

When I try to create a legend, it does only show one color. How can i add the two other colors to the legend when i only have one bar plot? My code looks like this:.

matlab legend multiple colors

Accepted Answer. Michael Haderlein on 8 May Another thing that changed starting in the Rb version is that the hold on and hold off automatically cycles through the colors.

In the past, each new plot command would start with the first color blue and you would have to manually change the color. Now it will automatically move to the next color s. See below for how to manually adjust the colors. If using mesh x,y,zto change the look of it you would want to change 'EdgeColor'. Note that the name of this colormap is "parula" while previous to Rb, it was "jet".

The eight basic colors are known by either their short name or long name RGB triplets are also included.

Editing colors in the legend

Long Name Short Name RGB Triplet blue b [0,0,1] black k [0,0,0] red r [1,0,0] green g [0,1,0] yellow y [1,1,0] cyan c [0,1,1] magenta m [1,0,1] white w [1,1,1]. Example of how to change the color using short names is below. You can easily do the same thing using the long names.

Many times you want to have more control of what colors are used. For example, I may want some data points drawn in the same color as the curve. Or I have a piece-wise graph that I want to have all the same color. There are several ways to do this. One is to use the default colors and "resetting" the order, which is shown here. Others involve using the RGB triplet see next section. As you may see, this could get confusing to keep track of.

Thus it may be easier to use the RGB triplets, and even name them ahead of time. This is discussed in the section below. Usually RGB colors have values from 0 to