How does matlab customize the colorbar

The setting of the colorbar is very important when matlab draws a plane distribution map. A good colorbar not only makes the image more beautiful, but also makes it easier for people to capture the information conveyed on the map. Students who have used matlab know that the default colormap of matlab is jet, that is, the color displayed by inputting "colorbar" after you draw the picture. In addition, matlab also comes with a lot of colormaps, such as hsv, autumn, bone, colorcube and so on. We can directly enter "colormap(hsv)" in the command window to display the corresponding colormap for the color of the floor plan.

The following teaches you how to customize the colormap you want, the method is very simple.

Take the sea surface temperature map of the China Sea as an example:

How does matlab customize the colorbar

This is a picture drawn by m_pcolor, and then the colormap is the default jet of matlab (that is, the colormap displayed by directly entering the command 'colorbar').

If we enter 'colormap(hsv)' in the command window, it will become the following picture:

How does matlab customize the colorbar

(Please ignore the title of the picture, the screenshot is very troublesome, sorry)

If we want to define a new colormap, and the colors are passed from red, orange, white, blue, and purple in turn (as shown in the figure below), what should we do?

How does matlab customize the colorbar

This uses matlab's colormap Editor.

As shown below: Click Edit-colormap in the figrue window

How does matlab customize the colorbar

The colormap Editor window appears:

How does matlab customize the colorbar

We can use this window to directly set a custom colormap.

There is a color scale in the colormap editor. There are some sliders below the color scale. The rectangular sliders at both ends are fixed and cannot be deleted; while the rectangle + triangle slider in the middle can be added, deleted, or slid. Click the left button of the mouse at the low end of the color scale to add, select a slider and press Delete to delete it, and hold down a slider to slide left and right.

In order to achieve the above-mentioned effect of "colors are transmitted sequentially from red, orange, white, blue, and purple", we first delete the two rectangles + triangle sliders in the middle, as shown in the following figure:

How does matlab customize the colorbar

Since both ends of the colormap in the previous picture are red, after the two sliders in the middle are deleted, only red is left in the entire colormap.

Let's start with white. There are 64 grids on the ruler. In order to balance the left and right, we first select the middle two grids to add white. The specific steps are:

1. Click below the middle color grid of the ruler, and a slider will appear (as shown in the figure below).

How does matlab customize the colorbar

2. Double-click the slider that appears, the color selection window will appear, and select white (as shown in the figure below).

How does matlab customize the colorbar

After selection, the image will look like this:

How does matlab customize the colorbar

In the same way, select "Red, Orange, Blue, Purple", as shown below:

How does matlab customize the colorbar

But at this time we found that the colormap was not what we wanted, because yellow and green appeared in the middle. We note that there is an Interpolating colorspace option in the colormap Editor. Since we are just based on colormap (hsv), the color interpolation method here is hsv, and we should choose RGB. As shown below:

How does matlab customize the colorbar

Alright, you're done.

The following is to save the colormap set by yourself so that you can use it directly when drawing in the future.

In the command transmission control input:

mycolor=colormap;%mycolor name is arbitrary

save mycolor mycolor;

The next time you draw a picture, just load mycolor first; then enter colormap(mycolor) to use this colorbar directly.

There is also a colorbar that is not gradient , as shown below:

How does matlab customize the colorbar

This colorbar is also set up in the same way. There are 5 colors in the colorbar in the picture, then we set the first five colors as the color in the picture in the colormap Editor, and then set the rest of the colors to white (not necessarily white, other colors are also acceptable, mainly for the convenience of identification)

How does matlab customize the colorbar

This is when we enter "colormap" in the command window, and a 64*3 array will appear.

How does matlab customize the colorbar

Note that the first five rows of the array represent the above five colors, and the rest [1 1 1] represent white. This is as long as the first 5 rows are copied and written into a new array.

How does matlab customize the colorbar

Then "save mycolor5 mycolor1" save it. This is to enter "colormap(mycolor5)" in the command window and the following image will appear:

How does matlab customize the colorbar

You're done! ! !

It's the first time to write matlab teaching, it's a bit long-winded, I hope it can help everyone! !


Go to http://blog.sina.com.cn/s/blog_68fff85f0102v4h1.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324858589&siteId=291194637
Recommended