intanfifizieana asked . 2023-10-20

How to change the scale of color bar to discrete ?

hi,
I have my contour plot like this figure,

change the scale of color bar to discrete

I want to change the scale of colorbar to a discrete one with the scale value [ 0, 0.1 ,0.2 ,0.3 ,0.4 ,0.5 ,0.6 ,0.7 ,0.75 ,0.8 ,0.85, 0.9 ,1]
how to do it?

MATLAB , Graphics , Formatting and Annotation , colorbar , contourplot

Expert Answer

John Williams answered . 2024-12-18 08:53:55

You can use a colormap that has duplicate colors wherever the spacing between the levels is 0.1:
 
 
x = [-7.22	-6.70	-6.19	-5.67	-5.15	-4.64	-4.12	-3.60	-3.09	-2.56	-2.04	-1.53	-1.00	-0.51	0.02	0.54	1.06	1.58	2.10	2.60	3.12	3.64	4.16	4.69	5.18	5.70	6.23	6.75	7.25];
y = [7.20	6.70	6.18	5.68	5.14	4.62	4.11	3.59	3.09	2.57	2.05	1.54	1.02	0.51	-0.01	-0.53	-1.03	-1.55	-2.07	-2.59	-3.09	-3.61	-4.14	-4.65	-5.16	-5.67	-6.19	-6.71	-7.22];
strain_12 = [0.48	0.64	0.66	0.7	0.68	0.72	0.76	0.78	0.9	0.88	0.86	0.82	0.88	0.84	0.9	0.88	0.9	0.86	0.88	0.82	0.82	0.8	0.8	0.78	0.76	0.72	0.7	0.68	0.64	0.5	0.64	0.66	0.76	0.68	0.76	0.76	0.78	0.82	0.82	0.8	0.8	0.82	0.84	0.88	0.84	0.86	0.84	0.86	0.8	0.78	0.74	0.72	0.74	0.74	0.72	0.72	0.68	0.64	0.54	0.7	0.68	0.76	0.7	0.68	0.7	0.74	0.76	0.72	0.8	0.86	0.84	0.9	0.92	0.86	0.88	0.86	0.86	0.84	0.8	0.76	0.74	0.7	0.7	0.74	0.72	0.7	0.68	0.48	0.68	0.72	0.74	0.72	0.7	0.7	0.76	0.82	0.82	0.86	0.88	0.84	0.88	0.88	0.88	0.86	0.88	0.9	0.94	0.9	0.86	0.82	0.78	0.76	0.76	0.76	0.76	0.7	0.48	0.66	0.7	0.68	0.7	0.72	0.7	0.74	0.76	0.76	0.82	0.88	0.84	0.84	0.86	0.8	0.82	0.84	0.82	0.88	0.88	0.9	0.88	0.82	0.76	0.78	0.74	0.8	0.72	0.48	0.66	0.68	0.66	0.7	0.78	0.8	0.82	0.82	0.8	0.84	0.9	0.92	0.86	0.84	0.8	0.82	0.82	0.82	0.86	0.92	0.9	0.88	0.82	0.76	0.76	0.74	0.78	0.7	0.5	0.62	0.54	0.56	0.64	0.78	0.86	0.82	0.82	0.82	0.78	0.82	0.86	0.82	0.8	0.82	0.82	0.82	0.8	0.82	0.84	0.82	0.78	0.78	0.74	0.72	0.68	0.7	0.64	0.52	0.62	0.54	0.58	0.64	0.76	0.84	0.82	0.8	0.82	0.8	0.82	0.84	0.84	0.84	0.82	0.8	0.78	0.76	0.76	0.76	0.76	0.76	0.72	0.74	0.7	0.68	0.7	0.7	0.48	0.6	0.58	0.62	0.66	0.76	0.86	0.8	0.78	0.8	0.78	0.82	0.84	0.84	0.82	0.82	0.8	0.8	0.78	0.76	0.78	0.78	0.8	0.76	0.74	0.72	0.7	0.72	0.68	0.48	0.62	0.66	0.7	0.74	0.74	0.78	0.72	0.74	0.74	0.74	0.8	0.76	0.78	0.78	0.8	0.76	0.74	0.74	0.78	0.78	0.8	0.78	0.76	0.74	0.78	0.76	0.8	0.72	0.46	0.62	0.7	0.76	0.76	0.78	0.82	0.72	0.76	0.74	0.76	0.78	0.76	0.76	0.82	0.82	0.78	0.76	0.78	0.82	0.78	0.8	0.78	0.8	0.78	0.78	0.78	0.76	0.68	0.44	0.6	0.7	0.72	0.7	0.7	0.68	0.68	0.74	0.72	0.74	0.72	0.72	0.74	0.78	0.82	0.82	0.82	0.8	0.82	0.78	0.82	0.78	0.8	0.74	0.74	0.7	0.7	0.62	0.44	0.64	0.72	0.7	0.7	0.68	0.64	0.72	0.76	0.8	0.8	0.76	0.76	0.78	0.78	0.8	0.8	0.78	0.76	0.76	0.78	0.8	0.78	0.78	0.76	0.72	0.72	0.68	0.64	0.4	0.62	0.7	0.72	0.72	0.68	0.66	0.72	0.72	0.76	0.78	0.74	0.78	0.82	0.8	0.8	0.8	0.78	0.76	0.74	0.8	0.78	0.76	0.74	0.72	0.68	0.68	0.66	0.64	0.42	0.58	0.68	0.72	0.76	0.72	0.7	0.74	0.76	0.76	0.74	0.74	0.74	0.78	0.76	0.78	0.78	0.8	0.78	0.76	0.78	0.74	0.72	0.74	0.7	0.7	0.72	0.7	0.7	0.38	0.52	0.62	0.68	0.7	0.72	0.74	0.8	0.8	0.82	0.76	0.76	0.76	0.76	0.8	0.78	0.76	0.78	0.78	0.76	0.76	0.74	0.76	0.76	0.74	0.76	0.72	0.7	0.68	0.36	0.5	0.62	0.66	0.72	0.78	0.8	0.82	0.78	0.78	0.7	0.74	0.76	0.74	0.8	0.76	0.72	0.78	0.78	0.78	0.8	0.82	0.78	0.76	0.72	0.74	0.72	0.72	0.7	0.38	0.54	0.62	0.64	0.7	0.76	0.74	0.8	0.8	0.8	0.74	0.8	0.8	0.76	0.82	0.76	0.76	0.8	0.82	0.8	0.84	0.86	0.82	0.78	0.74	0.78	0.74	0.72	0.72	0.4	0.6	0.66	0.66	0.7	0.7	0.7	0.76	0.74	0.76	0.74	0.76	0.84	0.82	0.84	0.78	0.8	0.82	0.84	0.8	0.82	0.82	0.76	0.74	0.74	0.78	0.7	0.66	0.66	0.44	0.64	0.7	0.66	0.66	0.64	0.68	0.72	0.7	0.76	0.76	0.78	0.82	0.8	0.8	0.82	0.84	0.82	0.8	0.82	0.8	0.8	0.76	0.74	0.74	0.72	0.7	0.66	0.66	0.46	0.66	0.74	0.72	0.66	0.68	0.7	0.68	0.66	0.72	0.76	0.8	0.86	0.86	0.82	0.84	0.82	0.78	0.78	0.84	0.84	0.78	0.78	0.76	0.74	0.72	0.72	0.64	0.68	0.48	0.68	0.78	0.78	0.72	0.74	0.76	0.74	0.68	0.64	0.72	0.8	0.84	0.9	0.84	0.84	0.8	0.8	0.84	0.88	0.88	0.82	0.76	0.78	0.76	0.68	0.7	0.68	0.7	0.42	0.62	0.74	0.74	0.74	0.76	0.78	0.78	0.8	0.78	0.84	0.86	0.86	0.9	0.86	0.84	0.82	0.8	0.86	0.9	0.92	0.84	0.84	0.82	0.8	0.74	0.74	0.72	0.72	0.36	0.56	0.66	0.72	0.76	0.74	0.8	0.8	0.8	0.78	0.84	0.82	0.8	0.86	0.84	0.8	0.8	0.8	0.84	0.88	0.9	0.86	0.82	0.82	0.8	0.74	0.72	0.72	0.72	0.3	0.48	0.58	0.6	0.64	0.68	0.72	0.74	0.78	0.8	0.8	0.78	0.76	0.82	0.82	0.78	0.78	0.78	0.8	0.84	0.86	0.84	0.82	0.78	0.78	0.74	0.72	0.74	0.72	0.28	0.44	0.58	0.64	0.7	0.72	0.72	0.7	0.72	0.76	0.76	0.82	0.8	0.88	0.84	0.8	0.74	0.74	0.74	0.84	0.82	0.8	0.8	0.8	0.76	0.74	0.68	0.66	0.66	0.32	0.48	0.62	0.66	0.7	0.7	0.72	0.74	0.76	0.76	0.76	0.8	0.8	0.86	0.86	0.84	0.74	0.74	0.74	0.82	0.82	0.82	0.78	0.78	0.8	0.74	0.7	0.66	0.68	0.32	0.5	0.66	0.72	0.74	0.8	0.8	0.8	0.8	0.78	0.8	0.84	0.86	0.88	0.92	0.9	0.84	0.78	0.84	0.9	0.9	0.9	0.84	0.84	0.82	0.78	0.74	0.68	0.66	0.34	0.54	0.7	0.74	0.76	0.8	0.78	0.78	0.8	0.78	0.8	0.82	0.84	0.9	0.96	0.96	0.9	0.84	0.86	0.9	0.86	0.88	0.82	0.82	0.82	0.76	0.76	0.74	0.68];
[a,b] = meshgrid(x,y);
gama_12 = reshape(strain_12,29,29);
shear = rescale(gama_12,0,1);
contourf(b,a,shear);
lvls = [ 0, 0.1 ,0.2 ,0.3 ,0.4 ,0.5 ,0.6 ,0.7 ,0.75 ,0.8 ,0.85, 0.9 ,1];
% find the indices where the level difference is "big" (0.1):
lvl_idx = find(diff(lvls) > 0.075); % (closer to 0.1 than to 0.05)
n_big = numel(lvl_idx);
% create a colormap with an extra color for each big level difference:
cmap = jet(numel(lvls)-1+n_big);
% change indices in lvls to indices in the colormap:
cmap_idx = lvl_idx;
for ii = 1:n_big
    cmap_idx(ii) = lvl_idx(ii) + nnz(lvl_idx <= lvl_idx(ii));
end
% duplicate the colors in the colormap at the big level indices:
cmap(cmap_idx,:) = cmap(cmap_idx-1,:);
% apply the colormap, create the colorbar, and set the ticks to lvls:
colormap(cmap);
cb = colorbar();
cb.Ticks = lvls;

change the scale of color bar to discrete


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.