Hello!
I am plotting a confidence band using fill, and get an error-message when using hecadecimal color:
I have tried with both 'Color' and 'FaceColor' before the hexadecimal color, without it helping. It works when I use a default color such as 'b'.
Also, when trying just to plot the line (not filling), it works with the html-code.
fill([0:hmax, fliplr(0:hmax)], [upper_bounds, fliplr(lower_bounds)], '#7E2F8E', 'FaceAlpha', 0.2, 'EdgeColor', 'none');
Thanks!

4 件のコメント

Stephen23
Stephen23 2024 年 6 月 16 日
編集済み: Stephen23 2024 年 6 月 16 日
The FILL documentation states that the C input argument supports "Patch colors, specified as a color name, RGB triplet, vector of colormap indices, or a matrix of colormap indices", and proceeds to give examples of all of those.
I do not see hexadecimal anywhere in that list.
Perhaps you were thinking of the FACECOLOR or EDGECOLOR name-value arguments, which do support hexadecimal:
Ulrikke
Ulrikke 2024 年 6 月 16 日
As i stated on the question, it did not work with Facecolor either
Stephen23
Stephen23 2024 年 6 月 16 日
"it did not work with Facecolor either"
Have you checked the documentation of your installed MATLAB version (i.e. not the online documentation). It is quite possible that hexadecimal was not supported in your installed version.
Ulrikke
Ulrikke 2024 年 6 月 16 日
I suppose it does, since when i tried to do a plot (not with fill, but with a line), it does work with hexadecimal

サインインしてコメントする。

回答 (2 件)

Hassaan
Hassaan 2024 年 6 月 16 日

1 投票

% Define the hexadecimal color
hexColor = '#7E2F8E';
% Convert hex color to RGB triplet
rgbColor = sscanf(hexColor(2:end), '%2x%2x%2x', [1 3]) / 255;
% Define your x and y values
hmax = 10; % Example hmax value
upper_bounds = rand(1, hmax+1) + 1; % Example data for upper bounds
lower_bounds = rand(1, hmax+1); % Example data for lower bounds
% Use fill with the RGB triplet
fill([0:hmax, fliplr(0:hmax)], [upper_bounds, fliplr(lower_bounds)], ...
rgbColor, 'FaceAlpha', 0.2, 'EdgeColor', 'none');

1 件のコメント

Star Strider
Star Strider 2024 年 6 月 16 日
Your approach for converting hex colours to RGB triplets:
% Convert hex color to RGB triplet
rgbColor = sscanf(hexColor(2:end), '%2x%2x%2x', [1 3]) / 255;
never occurred to me.
+1

サインインしてコメントする。

DGM
DGM 2024 年 6 月 16 日
編集済み: DGM 2024 年 6 月 16 日

0 投票

Didn't recall that working either.
X = [0 0 1 1];
Y = [0 1 1 0];
fill(X,Y,'','facecolor','#7E2F8E');

カテゴリ

ヘルプ センター および File ExchangeColor and Styling についてさらに検索

製品

リリース

R2022b

質問済み:

2024 年 6 月 16 日

コメント済み:

2024 年 6 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by