Generate data from plot - colormap

6 visualizzazioni (ultimi 30 giorni)
Zara Greer
Zara Greer il 8 Gen 2021
Commentato: Cris LaPierre il 8 Gen 2021
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 Commenti
Walter Roberson
Walter Roberson il 8 Gen 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.
Cris LaPierre
Cris LaPierre il 8 Gen 2021
@Kelly Kearney, I suggest moving your comment to an answer so it can be accepted.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Color and Styling in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by