Generate data from plot - colormap

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
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.
This looks like a spectrogram to me.
Zara Greer
Zara Greer le 8 Jan 2021
Is there no way to delete the rows using only the MATLAB figure? I see that the data is not the original data inputted but rather a matrix of RBG values, and then the x-axis and y-axis arrays. I can do the following to generate the RBG values:
fig=gcf;
RBGvalues = get(fig,'Colormap');
I then get a 256x3 double array for RBG values, showing a list of 3 columns with 3 values per row each representing a color. However I'm not sure how this color data is organized, or how I could delete the 5th and 6th rows of data and re-plot this colormap showing a y-axis of only rows 1-4.
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
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
Zara Greer le 8 Jan 2021
Of course! Figure attached. So the ylim solution almost works except there is a .5-width white space above the first trial now, which I included in the screenshot below.
Zara Greer
Zara Greer le 8 Jan 2021
Okay actually, I just used:
fig=gcf;
set(gca,'ylim',[.5 4.5]);
This worked perfectly and got me the following figure. Thanks for your help.
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 le 8 Jan 2021
@Kelly Kearney, I suggest moving your comment to an answer so it can be accepted.

Connectez-vous pour commenter.

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!

Translated by