How to Modify Contour Colors in MATLAB?

  • MATLAB
  • Thread starter eahaidar
  • Start date
  • Tags
    Matlab
In summary, the author is asking for help with color selection for a figure, and provides some background on MATLAB's built-in color functions.
  • #1
eahaidar
71
1
%gamma=20;
gamma=580;
%P=0.1;
P=0.75;
N=P.*gamma;
lamdazero=1550;
[lamdapump,lamdasignal] = meshgrid(1550:0.1:1700,1550:0.1:1700);
beta3=1.3;
beta4=-8*10^-4;
%beta3=0.06;
%beta4=-2*10^-4;
c=2*pi*3*10^8;
%L=1;
L=0.01;
A0=(1./lamdapump) -(1./lamdazero);
B0=(1./lamdapump) -(1./lamdasignal);
%Linearmismatch=beta2.*c.^2.*(B0).^2;
%beta2=(6*pi.*10^5.*beta3.*A0) +(0.5.*beta4.*A0.^2).*(6.*pi.*10^5)^2;
%Second0=(1./2).*beta2.*(c.^2).*(B0.^2);
Third0=10^-9.*beta3.*(c.^3).*A0.*(B0.^2);
Fourth0=10^-12.*beta4.*(1./2).*c.^4.*(A0.^2).*(B0.^2);
%S4=(10^-12/12).*beta4.*c.^4*(B0.^4);
Fourorder=(10^-12).*c.^4.*beta4.*(1/12).*(B0).^4;
g0=1.1*10^-11;
Aeff=11*10^-12;
PSBS=0.025;
%g0=3.9*10^-9;
%Aeff=14*10^-12;
%PSBS=0.005;
SBS=(g0.*PSBS.*1000)./Aeff ;
deltabeta=Third0+Fourth0+Fourorder;
hold on
for i=1:1:length(deltabeta)
for j=1:1:length(deltabeta)
if(deltabeta(i,j)>=0 || deltabeta(i,j)<=(-4*N))
test(i,j)=NaN;
else
test(i,j)=deltabeta(i,j);
end
end
end
contourf(lamdapump,lamdasignal,test,'ShowText','off');
cmap=[0,0,0];
colormap=cmap;
colorbar
h = colorbar;
set(get(h,'title'),'string','\Delta \beta (\gamma P)');
ax = findobj('type','axes');
%set(ax(1),'ytickl',{'-5172.4', '-4310.3', '-3448.3', '-2586.2', '-1724.1',' -862.1', '0', '862.1', '1724.1'})
xlabel('\lambda_p_u_m_p')
ylabel('\lambda_s_i_g_n_a_l')
title('Contour representing linear phase mismatch for FWM pump power 75 mW and SBS pump power 25 mW ')

Hello everyone I am new here and have small experience with MATLAB and would like some help. So when you execute this code you would see a curve I want this curve to be one color only. Any help with that? Because I would love to retain the original plot without removing points to get that curve. One more thing, I was wondering that if I want to add a condition or in other words a black color (since no black is in my color bar) like if deltabeta=-2 gamma P make deltabeta black colored is it possible Sorry for making you guys read that long. Thank you and looking forward to reading your reply. el-abed
 
Physics news on Phys.org
  • #2
For starters, you make built-in MATLAB functions into variables in several places here.

Code:
gamma=580;
colormap=cmap;

Both of these commands will override the MATLAB built-in functions. Don't do this, just use different variable names that don't conflict.

Once you use different variable names, you can set the colormap to whatever you want.

http://www.mathworks.com/help/matlab/ref/colormap.html
 

Related to How to Modify Contour Colors in MATLAB?

1. What is contourf in MATLAB?

Contourf is a function in MATLAB that creates filled 2D contour plots. It takes in data points and creates a smooth contour plot by interpolating between the points. The filled areas can be used to represent different levels or categories of data.

2. How do I use contourf in MATLAB?

To use contourf, you first need to have your data points stored in arrays. Then, you can use the function by specifying the x and y coordinates of the data points, as well as the data values. You can also customize the appearance of the plot by specifying parameters such as the colormap, contour levels, and labels.

3. Can I add a colorbar to my contourf plot?

Yes, you can add a colorbar to your contourf plot by using the colorbar function in MATLAB. This will add a vertical or horizontal bar on the side of your plot, indicating the color scale corresponding to the data values.

4. What is the difference between contourf and contour?

The main difference between contourf and contour is that contourf creates a filled contour plot, while contour creates a line contour plot. This means that the areas between the contour lines in contourf are filled with color, while they are left blank in contour.

5. Can I save my contourf plot as an image file?

Yes, you can save your contourf plot as an image file by using the saveas function in MATLAB. This allows you to save your plot as a variety of image formats such as PNG, JPEG, or PDF. You can also specify the resolution and size of the image.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
Replies
7
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
2K
Replies
2
Views
3K
Back
Top