How to get the rgb code from Matlab figure

조회 수: 46 (최근 30일)
Khalid Ibne Masood
Khalid Ibne Masood 2020년 4월 29일
편집: Adam Danz 2020년 4월 29일
Hello Everyone,
I have attached a matlab figure here. This plot was generated from Matlab and I need to know the RGB color code for each color used in this picture. I know that there are exactly 5 colors have been used for this plot, I need to extract these 5 colors. Please help me to solve this problem.
Thank you.
Khalid
  댓글 수: 2
Adam Danz
Adam Danz 2020년 4월 29일
편집: Adam Danz 2020년 4월 29일
Do you have the fig file (if so, attach it) and do you know which function was used to generate the plot?
Khalid Ibne Masood
Khalid Ibne Masood 2020년 4월 29일
Hello Adam,
Thank you, here I have attached the .fig file.
I believe 'surf' was used to generate the plot.
Thank you.
Khalid

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

채택된 답변

Adam Danz
Adam Danz 2020년 4월 29일
편집: Adam Danz 2020년 4월 29일
Retreiving the colors from a surface plot can be trickly due to the interaction between the color properties of a surface object. If you plan to apply this solution to a variety of surface plots with varying color properties, you'll need to carefully read about the color properties and how they interact with eachother: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.surface-properties.html#d120e1097631
See inline comments for details.
% Open the figure
fig = openfig('Question.fig');
% Find the axis handle
ax = findobj(fig, 'Type', 'axes');
% Find the surface handle
surfObj = ax.Children;
% Get the colormap
cmap = ax.Colormap;
% scale the color data values to the range of the
% colormap to match the color data with the colormap rows.
cval = round((surfObj.CData - ax.CLim(1))./range(ax.CLim) .* (size(cmap,1)-1)) +1;
% List the unique colors in order from left to right.
uniqueRGB = cmap(unique(cval(:),'stable'),:);
Results:
uniqueRGB =
0.5 0 0
0.9375 1 0.0625
0.5625 1 0.4375
0.4375 1 0.5625
0 0 0.5625
Plot a large dot above each color section to check the results
% Add dots to plot to confirm color
hold on
h = scatter3([.1 .35 .6 .80 .95], repmat(1,1,size(uniqueRGB,1)), repmat(max(ax.ZLim),1,size(uniqueRGB,1)), ...
200, uniqueRGB, 'filled', 'MarkerEdgeColor', 'k', 'LineWidth', 2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by