Generate data from plot - colormap
Afficher commentaires plus anciens
I have a colormap MATLAB figure and have to get the data from that colormap so that I can edit it. All I need to do is remove two rows from the colormap. Right now the colormap has rows 1-6, and I want it to show data only from rows 1-4. 

8 commentaires
Cris LaPierre
le 8 Jan 2021
The colormap is not determining the rows. Your data is. Colormaps determine the colors used, which can be seen in the colorbar to the right.
Zara Greer
le 8 Jan 2021
Kelly Kearney
le 8 Jan 2021
As Chris commented, the colormap is not the same as the color data. The colormap just tells the plot how to covert from data value to color; it's always an n x 3 matrix, regardless of what type of data is being plotted or how that data is being plotted.
To figure out what's actually being plotted, you probably want to look at the XData, YData, and CData properties of the axis in question. You can modify those to change what's being plotted.
Or, more simply, just change the y-axis limits to hide the last two rows:
set(gca, 'ylim', [0 4.5]);
Cris LaPierre
le 8 Jan 2021
Modifié(e) : Cris LaPierre
le 8 Jan 2021
Much easier to work with actual data. Can you attach your fig file to your post? Use the paperclip icon.
Setting ylim is about as simple a solution as there is.
Zara Greer
le 8 Jan 2021
Zara Greer
le 8 Jan 2021
Walter Roberson
le 8 Jan 2021
A colormap is an n x 3 array of data.
There is more than one way that colormaps can be used.
In one mode, the input is expected to be non-negative integers, and the (value plus 1) is used as the index into the colormap to determine which color to output corresponding to the location.
In another, more common mode, with the default settings, the maximum and minimum of the data to be presented are calculated, and floor((data - minimum)./(maximum minus minimum) * (number of colors)) + 1 is calculated and used as the index into the colormap -- so the smallest data value is mapped to the first color in the map, and the largest value is mapped to the last color in the map, and everything between is mapped linearly -- half way through the data range would be mapped to half way through the color map for example. When I look at the colorbar, I believe this kind of color mapping is what has been done for this figure.
You can reduce the number of colors in a colormap by using colormap() with a smaller map. For example,
cmap = colormap(); %fetch current
colormap(cmap(1:4,:)) %use only the first four colors
I doubt that is what you want, however. It looks to me as if you only want the first four
values, which is a very very different matter, probably most easily handled by using ylim.
values, which is a very very different matter, probably most easily handled by using ylim.
Cris LaPierre
le 8 Jan 2021
Réponses (0)
Catégories
En savoir plus sur Color and Styling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!