Hi.
What code do I need to change meshgrid face color to 'transparent'?
Thank you.
N = 100; % Size Of Interpolation Vectors/Matrices
Ltv = linspace(min(W(:,1)), max(W(:,1)), N); % Latitude Vector For Interpolation
Lnv = linspace(min(W(:,2)), max(W(:,2)), N); % Longitude Vector For Interpolation
[Ltm,Lnm] = meshgrid(Ltv, Lnv); % Matrices For Interpolation
Pm = griddata(W(:,1), W(:,2), W(:,3), Ltm, Lnm); % Interpolate
figure
surf(Ltm, Lnm, Pm)
colorbar;
grid on
view(40,40)
xlabel('Latitude')
ylabel('Longitude')
zlabel('Total Precipitation (mm)')

 Réponse acceptée

Sindar
Sindar le 22 Avr 2020

1 vote

surf(Ltm, Lnm, Pm,'FaceAlpha',0.5)
to set transparency to 50%. See other options here

5 commentaires

Ayush singhal
Ayush singhal le 27 Avr 2021
in the below code, I would like to change the z axis values. So that cube looks good. Is it possible to set the z axis range from 0 to 10?
Any lead would be helpful.
x y] = meshgrid(-10:2:12); % Generate x and y data
z = zeros(size(x,2)); % Generate z data
surf(x, y,z,'FaceAlpha' , 0.1) % Plot the surface
view(2)
axis on
%
hold on
vert = [0 0 0;10 0 0;10 10 0;0 10 0;0 0 6;10 0 6;10 10 6;0 10 6];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0);
view(3)
axis vis3d
% rotate3d
xlabel('x')
ylabel('y')
zlabel('z')
If I understand correctly, all you need is zlim([0 10]). Also a good idea not to hard-code the vertices
[x, y] = meshgrid(-10:2:12); % Generate x and y data
z = zeros(size(x,2)); % Generate z data
surf(x, y,z,'FaceAlpha' , 0.1) % Plot the surface
view(2)
axis on
%
hold on
L_x = 10;
L_y = 10;
L_z = 6;
vert = [0 0 0;L_x 0 0;L_x L_y 0;0 L_y 0;0 0 L_z;L_x 0 L_z;L_x L_y L_z;0 L_y L_z];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0);
view(3)
axis vis3d
% rotate3d
xlabel('x')
ylabel('y')
zlabel('z')
zlim([0 10])
Ayush singhal
Ayush singhal le 28 Avr 2021
Thanks, It works.
But still why cube is looking like so verticle. Even the height (6) is less then the lenght and width.
how to make a square cube. If I put all dimenion same then also it looks like too verticle.
[x, y] = meshgrid(-20:2:20); % Generate x and y data
z = zeros(size(x,2)); % Generate z data
surf(x, y,z,'FaceAlpha' , 0.1) % Plot the surface
view(2)
axis on
%
hold on
L_x = 10;
L_y =10;
L_z = 10;
vert = [0 0 0;L_x 0 0;L_x L_y 0;0 L_y 0;0 0 L_z;L_x 0 L_z;L_x L_y L_z;0 L_y L_z];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0);
view(3)
axis vis3d
% rotate3d
xlabel('x')
ylabel('y')
zlabel('z')
zlim([-1 10])
xlim([-10 10])
ylim([-10 10])
Use axis equal:
[x, y] = meshgrid(-10:2:12); % Generate x and y data
z = zeros(size(x,2)); % Generate z data
surf(x, y,z,'FaceAlpha' , 0.1) % Plot the surface
view(2)
axis on
%
hold on
L_x = 10;
L_y = 10;
L_z = 6;
vert = [0 0 0;L_x 0 0;L_x L_y 0;0 L_y 0;0 0 L_z;L_x 0 L_z;L_x L_y L_z;0 L_y L_z];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat', ...
'FaceAlpha', 0);
view(3)
axis vis3d equal
% rotate3d
xlabel('x')
ylabel('y')
zlabel('z')
xlim([-10 10])
ylim([-10 10])
zlim([-1 10])
Ayush singhal
Ayush singhal le 28 Avr 2021
Thanks a lot. It works perfect.
[x, y] = meshgrid (-10: 1: 12); % Generate x and y data
z = zeros (size (x, 2)); % Generate z data
surf (x, y, z, 'FaceAlpha' , 0.1) % Plot the surface
view (2)
axis on
%
hold on
L_x = 4;
L_y = 4;
L_z = 4;
vert = [0 0 0; L_x 0 0; L_x L_y 0; 0 L_y 0; 0 0 L_z; L_x 0 L_z; L_x L_y L_z; 0 L_y L_z];
fac = [1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8];
patch ( 'Vertices' , vert, 'Faces' , fac, ...
'FaceVertexCData' , hsv (6), 'FaceColor' , 'flat' , ...
'FaceAlpha' , 0.3);
view (3)
axis vis3d equal
% rotate3d
xlabel ( 'x' )
ylabel ( 'y' )
zlabel ( 'z' )
xlim ([-4 8])
ylim ([-4 8])
zlim ([- 1 10])
########
Now thw below code generates stripe pattern. Major problem is that to put those stripes onto the above code image( where cube is on the image plane). I want something like that is shown in screenshot.
If I am adding this code in the above mentioned code then meshgrid is going to disapper.
screenSize = get(0, 'MonitorPositions')
screenWidth = screenSize(3)
screenHeight = screenSize(4)
stripeWidth = 50; % Pixels
oneCycle = repelem([0,1], stripeWidth);
% Make vertical stripes.
numStripes = floor(screenWidth / (2* stripeWidth))
multipleCycles = uint8(255 * repmat(oneCycle, [screenSize(4), numStripes]));
cmap = [1 1 1; 0 0 0];
S= imrotate(multipleCycles,-45)
imshow(S, [], 'ColorMap', cmap);
axis on;

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by