Using this command, axis([XMIN XMAX YMIN YMAX] we can set range of both x and y axis.
Is there any way by which only one particular axis of plot is scaled while other is set at auto-scaling?
Check xlim, ylim and zlim for manually setting the limits of every axis.
For example:
x = 0:0.1:2*pi;
y = sin(x);
plot(x,y);
XMIN = 0;
XMAX = pi;
xlim([XMIN XMAX]);
This is the output:
Related
I have the following normal distribution and i need to set the graph plot to 1.5 on y axis.
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
ylim([0 1.5])
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
Could someone tell me how to? Regards
The axis function is the one you need.
you can set the axis to the values you want using
axis([xmin xmax ymin ymax])
or you can play with it doing things like:
axis equal
axis tight
axis off
etc
Go to the documentation for more info:
http://www.mathworks.co.uk/help/matlab/ref/axis.html?refresh=true
Try this,
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
ylim([0 1.5])
I'm trying to use imshow command to show an image. What I could not come up with is to label image axis according to my x and y values. My code is below:
[X,Y] = meshgrid(0:0.01:1,0:0.01:1);
u = 5;
v = 1;
z = sin(2*pi*(u*X+v*Y));
imshow(z);
axis on
When I use "axis on", it shows 0 to 100. But I want is 0 to 1.
You can specify x- and y-axis values in imshow as follows:
imshow(z, 'XData', 0:.01:1, 'YData', 0:.01:1)
(and then you of course need axis on as in your code).
I have the following normal distribution and i need to set the graph plot to 1.5 on y axis.
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
ylim([0 1.5])
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
Could someone tell me how to? Regards
The axis function is the one you need.
you can set the axis to the values you want using
axis([xmin xmax ymin ymax])
or you can play with it doing things like:
axis equal
axis tight
axis off
etc
Go to the documentation for more info:
http://www.mathworks.co.uk/help/matlab/ref/axis.html?refresh=true
Try this,
x = -.5:0.0001:3.5;
m1 = 1;
s1 = 0.5;
pdfNormal_1 = normpdf(x, m1, s1);
set(gcf,'color','w');
plot(x, pdfNormal_1)%, x, pdfNormal_2);
ylim([0 1.5])
I'm trying to make grid in my plot, i have other simpler plots where i manage to show grids, but not in this plot:
%The AXES command selects the set of axes to plot in,
axes(handles.viewCAM_handles.axes_accVelRatio);
% Plot velV and accV ratio with centered x and y axis
[AX] = plot(velV, accV);
grid on;
set(AX, 'LineWidth', 2);
xlabel('Velocity');
ylabel('Acceleration', 'Color', 'b');
xMax = max([max(velV) abs(min(velV))]);
yMax = max([max(accV) abs(min(accV))]);
if xMax >= 1
xMax = ceil(xMax);
else
xMax = round(xMax*10)/10;
end
if yMax >= 1
yMax = ceil(yMax);
else
yMax = round(yMax*10)/10;
end
axis([-xMax xMax -yMax yMax]);
y=get(gca,'ytick');
x=get(gca,'xtick');
hold on
Lx=line([x(1) x(length(x))],[0 0]);
Ly=line([0 0],[y(1) y(length(y))]);
set(Lx,'color','k');
set(Ly,'color','k');
for i=1:length(x)
plot(x(i),0,'kx');
text(x(i),-.01,num2str(x(i)));
end
for i=1:length(y)
plot(0,y(i),'kx');
text(-0.5,y(i),num2str(y(i)));
end
grid on;
set(gca,'yticklabel',[],'xticklabel',[],'ytick',[],'xtick',[]);
I'm setting origo in the middle of the plot and i draw lines for that, i think the problem has something to do with that. Any ideas?
I have tried putting "grid on" in other places in this code but i can't manage to show grid.
the grid lines are related to the x and y ticks of the axis.
So you could either change the line where you delete the ticks:
set(gca,'yticklabel',[],'xticklabel',[],'ytick',[],'xtick',[]);
to solely clear the labels
set(gca,'yticklabel',[],'xticklabel',[])
or you have to plot grid manually using lines (see http://www.mathworks.com/matlabcentral/answers/102945-how-can-i-specify-the-spacing-between-minor-tick-marks-and-minor-grid-lines-in-my-figures-in-matlab).
I have a matrix that stores x, y and z values as so:
{x1, y1, z1},
{x2, y2, z2},
{x3, y3, z3},
etc...
I need to interpolate the data, and plot in on a 2d graph, with color representing the z value. (example)
Any ideas?
Thanks!
Something like griddata might help you to interpolate:
x = vector(:,1);
y = vector(:,2);
z = vector(:,3);
% Settings
xres = 800; % Resolution, the higher, the smoother
yres = 800;
cm = 'default'; % Colormap
% Axes Limits
xmin = min(x);
ymin = min(y);
xmax = max(x);
ymax = max(y);
xi = linspace(xmin, xmax, xres);
yi = linspace(ymin, ymax, yres);
% Figure
myfig = figure('Position', [200 200 800 600]);
rotate3d off
[XI, YI] = meshgrid(xi, yi);
ZI = griddata(x, y, z, XI, YI, 'cubic');
mesh(XI,YI,ZI);
than you just need to change the view of it to only display a certain plane for a fixed value of z
In addition to #Alexandrew answer you can use newer and faster TriScatteredInterp class instead of GRIDDATA. For your exampe you can use 2D IMAGESC instead of 3D MESH.
%# insert the code from #Alexandrew answer to generate meshgrid
[XI, YI] = meshgrid(xi, yi);
TSI = TriScatteredInterp(x,y,z);
ZI = TSI(XI,YI);
imagesc(ZI)
colorbar
If your input matrix is a cell array, you can convert it to a numeric matrix with a = cell2mat(a);