How to get the rgb code from Matlab figure
61 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Khalid Ibne Masood
le 29 Avr 2020
Modifié(e) : Adam Danz
le 29 Avr 2020
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 commentaires
Réponse acceptée
Adam Danz
le 29 Avr 2020
Modifié(e) : Adam Danz
le 29 Avr 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!