File Exchange Pick of the Week

Our best user submissions

Convert between RGB and Color Names

Will‘s pick this week is Convert between RGB and Color Names by Stephen Cobeldick.

A fairly common challenge I encounter is the need for more plot colors. I have too many lines on my plot, and MATLAB begins to cycle back through colors it has already used. There are plenty of coping mechanisms for the situation. When I’ve cobbled my own solution together in the past, I always encounter a related challenge of deciding what extra colors to add. I’ve often found myself on a website toying with RGB values till I settle on one I like.

Stephen’s submission provides an easy way to use determine an RGB combination based on a recognizable name. You choose from one of 28 palettes, each of which contain a lexicon of color names to choose from. I went with xkcd, which contains 949 preconfigured colors, everything from “Yellowy Green” to “Yellow/Green” to “Yellowish Green.” (There are some non-yellow/green ones too). Want to know what they look like, call COLORNAMES_VIEW to get a figure window browser:

xkcd Colornames View

Once you have a color that speaks to you, you can call COLORNAMES to get the RGB vector that corresponds to it. I flipped the output arguments around so that I could inline a call directly in a plot command. Turns out this is what a sine wave of dried blood looks like:

Dried Blood Line

One fact that really impressed me is that Stephen continues to support this submission more than 4 years after he first uploaded it. Just last month, he tweaked it for R2018b compatibility. Major kudos for maintaining your work!

Two minor suggestions I would offer for the next update. One would be to include support for strings in addition to character arrays. And also consider adding Sherwin-Williams as a palette. Nothing will be more amusing than to plot with Brainstorm Bronze or Bungalow Beige.

Let us know what you think here or leave a comment for Stephen.

  • print


댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.