Why doesn't matlab have more plot colors?

조회 수: 160 (최근 30일)
Mackenzie Fraser
Mackenzie Fraser 2023년 7월 4일
댓글: DGM 2023년 7월 5일
I think MATLAB is a great way to process and present data, but one thing that really continues to frustrate me is the lack of options for plot colors. I prefer MATLAB over Python, but I think this is one thing that Python really has MATLAB beat on. In particular since the 8 colors tend to clash with each other and don't make for easy graph readability. You also cannot see white and yellow is difficult to see. Sure, you can input hex color codes, but that makes it endlessly more complicated and it would be so much easier if there were more color options. Why hasn't MATLAB changed this yet? Does anyone know?
  댓글 수: 1
Stephen23
Stephen23 2023년 7월 4일
편집: Stephen23 2023년 7월 4일
"I prefer MATLAB over Python, but I think this is one thing that Python really has MATLAB beat on"
This is comparing apples with oranges: Python does not do any plotting, Python does not support any plot colors.
Of course you can download, install, and import third-party modules/libraries that do plotting. In fact, those modules don't really plot either: the modules themselves rely on some standard gui engines... which do the plotting and let you use lots of colors to your heart's content. But Python itself does not plot nor have any colors. Not all users install those third-party modules.
In contrast, MATLAB does plot, straight out of the box. With colors. And much like Python (with its many third-party modules), MATLAB is designed to be extensible: there is even a large exchange of MATLAB extensions here, many of which could be considered "standard" for many users:
You will find plenty of colormap and line colororder functions there.

댓글을 달려면 로그인하십시오.

답변 (4개)

Image Analyst
Image Analyst 2023년 7월 4일
편집: Image Analyst 2023년 7월 4일
Well there are 16 million colors and you can use any of them just by specifying the color as a row in a 2-D matrix of the colors you've created. Plus you can create those colors in just one line of code if you want to use one of the numerous built-in colormaps. See code below:
numColors = 50; % Up to 16.7 million.
% Create a list of colors [r, g, b]
plotColors = turbo(numColors);
% Create a list of x,y points
x = cos(linspace(0, pi/2, numColors));
y = sin(linspace(0, pi/2, numColors));
% Plot data in those colors
for k = 1 : numColors
plot([0, x(k)], [0, y(k)], '-', 'Color', plotColors(k,:), 'LineWidth', 2)
hold on;
end
caption = sprintf('%d plots with %d unique colors', numColors, numColors);
title(caption)
If you don't specify the colors, you can still redefine the default built-in list of colors if you want. Just see attached demo.

Rik
Rik 2023년 7월 4일
You can provide your own palette to be used when plotting with the colororder function.
figure
hold on
newcolors = {'#F00','#F80','#FF0','#0B0','#00F','#50F','#A0F'};
colororder(newcolors)
for r=1:7
x = linspace(0,r,500);
y = sqrt(r.^2-x.^2);
plot(x,y,'LineWidth',15)
end
  댓글 수: 3
Rik
Rik 2023년 7월 4일
I don't know why they don't have more named colors, but I can image color names will invite controversy, so they just allow hex codes if you want more.
There are probably dozens of file exchange submission that provide more names colors. This one was my top hit on Google. It apparently contains "the 657 default colors from R", so that should suit your needs if colororder doesn't.
Stephen23
Stephen23 2023년 7월 4일
"but why doesn't matlab have more colors built in so that it's easier to make plots with different colors"
Python doesn't have any colors built in.

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2023년 7월 4일
If there are specific colors that you believe should be named, for which there's a somewhat agreed upon definition of what RGB values make up that color (sometimes more difficult than you might think), and for which the name would not conflict with an existing color name or marker symbol (so for example no 'o' for 'orange' since that would conflict with 'o' for circle markers in a line specification) please send your suggestion to Technical Support directly using this link and ask the Support staff to file it as an enhancement request.
Alternately, you could write a function (or a class with Constant properties) that returns an RGB triplet for your color and use that to specify the value of the Color property of a line or other graphics object. The uisetcolor color picker can help you identify the RGB triplet for the specific color you want to define.
plot(1:10, 1:10, 'LineWidth', 4, 'Color', purple)
function c = purple
c = [0.75, 0.25, 0.5]; % Mostly red, a little green, and a medium amount of blue
end
  댓글 수: 1
Image Analyst
Image Analyst 2023년 7월 4일
Really fun site to play around with. https://colorthesaurus.epfl.ch/
They did a survey of what people in different countries call colors.

댓글을 달려면 로그인하십시오.


DGM
DGM 2023년 7월 4일
편집: DGM 2023년 7월 4일
I don't really care for it either,, but I should emphasize that it's not like there's some singular standard convention for color names or even how many colors should be named.
Stephen's colornames() is about as comprehensive as it gets.
Alphabet: 26 names
AmstradCPC: 27 names
AppleII: 16 names
Bang: 678 names
BS381C: 97 names
CGA: 16 names
Crayola: 222 names
CSS: 141 names
dvips: 68 names
Foster: 870 names
HTML4: 16 names
ISCC: 267 names
Kelly: 22 names
MacBeth: 24 names
MATLAB: 8 names
Natural: 6 names
R: 549 names
RAL: 213 names
Resene: 3132 names
Resistor: 13 names
SherwinWilliams: 1535 names
SVG: 140 names
Tableau: 10 names
Thesaurus: 240 names
Trubetskoy: 22 names
Wikipedia: 967 names
Wolfram: 24 names
X11: 549 names
xcolor: 19 names
xkcd: 949 names
Which one is best? Which one is correct? What color is mauve? Is 'y' the same color as 'yellow'? Is 'red' [1 0 0] or is it [0.898 0 0]?
The default 8 colors are simple to a fault -- the eight corners of the RGB cube. Are they equally useful for the same things? No. Are they really all that useful at all? Not all that much. They're a legacy convenience that is primarily convenient because there are so few of them. Recall that these unambiguously abbreviate to single character names. By virtue of their positions in RGB, they're about the least-subjective english-language names you can find. After all, what color is "Zeus" (yes, that's a color name).
I think the more contemporary thought is that plot colors should be sourced from the lines() color table, not from this old handful of named colors. Of course, lines() is pretty short too.
Regardless of why it came to be or what you or I think "should be", it's currently the way it is. You could submit an enhancement suggestion, but that's not going to help you today and tomorrow. If you have an idea what you want and what you're used to, build yourself a colormap to use in place of lines() and/or find/build a colorname lookup tool that caters to your preferred expectations.
IIRC, matplotlib uses a mix of X11/CSS/xkcd/Tableau names, so Stephen's colornames() should be able to cover that. If you prefer a more succinct inline usage, it should be easy enough to make a simple wrapper function for it.
  댓글 수: 3
DGM
DGM 2023년 7월 5일
For line plots, the categorical/qualitative maps from Brewer/MPL are fair enough depending on what I want.
The grouped maps like tab20 work nicely when they can be leveraged to add extra organization to a large set of plotted lines, but a lot of times it's easier to just generate custom ones. Then again, I'm wary to encourage cramming a ridiculous number of lines into a figure, because I know people do it.
DGM
DGM 2023년 7월 5일
FWIW, here's a swatch chart for everything in colornames(). It's kind of a giant image, but it's often handy to just be able to browse to see the range of tones in a given palette. The individual swatches aren't named for purposes of compactness.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by