Matlab: Using imshow and mesh in the same plot

In summary, to have one subplot in a greyscale color map and the other in a different color map, you can use the 'colormap' function to set a specific color map for each plot.
  • #1
kellis_115
1
0
Hi,
I have written a piece of code to plot a greyscale image using imshow and a mesh plot using mesh in the same plot (the graphs are subplots in the smae figure. My problem is that when I use imshow the meshplot turns to greyscale rather than colour, and I can't worj out how to have one plot as greyscale and the other as colour.

My code is below if this helps;

%Script to show diffraction grating
clear all

M=dlmread('testslit5.txt','\t');

subplot(2,1,1),imshow(M);
title('Diffraction grating');

Mtransform=fft2(M);
Mtransform=fftshift(Mtransform);
N=max(max(Mtransform));
Mtransform=Mtransform/N;

subplot(2,2,3),mesh(abs(Mtransform));
title('Diffraction grating diffraction pattern (intensity)');
subplot(2,2,4),mesh(angle(Mtransform));
title('Diffraction grating diffraction pattern (phase)');

Thanks in advance
 
Physics news on Phys.org
  • #2
.You can use the 'colormap' function to set a different color map for each plot. For example, to set the colormap for the mesh plot to be 'jet' and the colormap for the imshow plot to be 'gray', you could do the following:subplot(2,1,1),imshow(M, 'colormap', gray);title('Diffraction grating');Mtransform=fft2(M);Mtransform=fftshift(Mtransform);N=max(max(Mtransform));Mtransform=Mtransform/N;subplot(2,2,3),mesh(abs(Mtransform), 'colormap', jet);title('Diffraction grating diffraction pattern (intensity)');subplot(2,2,4),mesh(angle(Mtransform), 'colormap', jet);title('Diffraction grating diffraction pattern (phase)');
 

Related to Matlab: Using imshow and mesh in the same plot

1. How do I use the imshow and mesh functions together in Matlab?

To use the imshow and mesh functions in the same plot, you can use the hold on command to plot multiple functions on the same figure. First, use the imshow function to plot your image, then use the hold on command. Finally, use the mesh function to plot your mesh on top of the image.

2. Can I customize the appearance of the mesh in the combined plot?

Yes, you can customize the appearance of the mesh by using the various input arguments in the mesh function. For example, you can change the color, line style, and line width of the mesh to suit your needs.

3. How can I add a colorbar to the combined plot?

To add a colorbar to the combined plot, you can use the colorbar function. This will create a colorbar that corresponds to the scale of the imshow function. If you want to customize the colorbar, you can use the various input arguments in the colorbar function.

4. Is it possible to add multiple meshes to the combined plot?

Yes, you can add multiple meshes to the combined plot by using the hold on command and then using the mesh function multiple times. This will plot each mesh on top of the previous one, creating a layered effect.

5. Can I save the combined plot as a figure in Matlab?

Yes, you can save the combined plot as a figure in Matlab by using the saveas function. This will allow you to save the entire figure, including the image, mesh, and any other added elements, as a separate file for future use.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • Programming and Computer Science
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
Back
Top