How to turn off (totally) a yaxis in a Matlab figure?
Google only tell me how to create an extra yaxis.
Appreciate any help.
Use the axis handle to modify either y axis.
hfig=figure;
hax=axes;
yyaxis(hax,'left')
hax.YAxis(1).Visible='off'; % Removes left axis
hax.YAxis(2).Visible='off'; % Removes right axis
Related
I'm the MatLab newbie and I need some help to create a linear and non-linear axis in one chart.
I need to make chart with 2 different X-axes. One X-axis displays 1000/T at the bottom and the second X-axis displays a T at the top of the chart.
Example figure:
Do you have any idea how to solve this problem in MatLab?
Thanks.
This can be done by simply creating a second axes object at the same place as the first. Let's first create some data:
x1 = 1:0.1:3.5;
x2 = 1./x1;
y = (0.5*(x1-2)).^3;
Now we can create a normal plot with the first axes, and get the axes handle:
plot(x1,y,'-r');
ax(1) = gca;
Then we create the second axes object, at the same position as the first, and make the color none so it is transparent and the plot from below is still visible. As this adds a second Y axis too, we simply remove the Y ticks of the second axis.
ax(2) = axes('Position',ax(1).Position,'XAxisLocation','top','Color','none');
set(ax(2),'YTick',[]);
Now lets just format the second X axis as we like. Let's set the limits to the minimum and maximum of the x2 vector, and make it logarithmic:
set(ax(2),'XLim',[min(x2),max(x2)]);
set(ax(2),'XScale','log');
Now we still have the problem that the XTicks of ax(1) are also displayed at the top, and the XTicks of ax(2) are displayed at the bottom. This can be fixed by removing the box around the existing axes and creating a third axis without any ticks but with a box.
box(ax(1),'off');
box(ax(2),'off');
ax(3) = axes('Position',ax(1).Position,'XTick',[],'YTick',[],'Box','on','Color','none');
Now finally we can link the axes to be able to zoom correctly
linkaxes(ax);
And that should be it...
There is documentation for having a graph with two y-axes on the Mathworks website . .
http://de.mathworks.com/help/matlab/creating_plots/plotting-with-two-y-axes.html
It should be trivial to covert the concepts to the x-axis.
Hello I would like to display an axis centered on [0,0,0] of a scatter 3 plot.
Is there a way to do this using the line function?
http://au.mathworks.com/help/matlab/ref/line.html
Not quite sure how to interpret it. Would greatly appreciate a hand.
If you just need the axes try adding:
hold on;
line(xlim,[0,0],[0,0]);
line([0,0],ylim,[0,0]);
line([0,0],[0,0],zlim);
After your scatter plot.
EDIT:
If you want to place the axes with origin at another point, you can do as follows:
hold on;
line(xlim,[origin(2),origin(2)],[origin(3),origin(3)]);
line([origin(1),origin(1)],ylim,[origin(3),origin(3)]);
line([origin(1),origin(1)],[origin(2),origin(2)],zlim);
Where origin is the point where you want the axes to meet.
I struggle a little bit with overlapping axis numbers of the y and x axis like it is shown in the image. I'd like to keep the size of the numbers and therefore think that simply shifting the numbers away from the axis itself would be an appropriate way to handle this issue.
Is there a possibility to do that?
Thanks in advance,
Joe
Here is a little workaround using text annotations. Basically you clear the current XTick labels and replace them with similar labels, but you can specify the distance from the axis:
clc
clear
close all
x = 1:20;
hPlot = plot(x,sin(x));
set(gca,'xaxisLocation','top');
set(gca,'XTickLabel',[]); %// Clear current XTickLabel
ylim = get(gca,'YLim'); %// Get y limit of the plot to place your text annotations.
for k = 2:2:20
text(k,ylim(2)+0.1,num2str(k),'HorizontalAlignment','Center') %// Play with the 'ylim(1) -0.1' to place the label as you wish.
end
Giving this:
Of course now it's exaggerated and you can do the same for the y axis if you want (using the 'XLim' property of the current axis,gca).
I just can't find it. How to set up axis and labels in matlab so they cross at zero point, with the labels just below the axis not on left/bottom of the plot ?
If I didn't make myself clear - I just want the plot to look like like we all used to draw it when in school. Axes crossing, 4 quadrants, labels right below axis, curve ... as it goes.
Anyone knows how to set it up ?
You should check out two submissions on The MathWorks File Exchange:
PlotAxisAtOrigin by Shanrong Zhang
axescenter by Matt Fig
Hopefully these will work with whatever MATLAB version you have (the submission from Matt Fig is the most recently updated one).
As of Matlab release R2015b, this can be achieved with the axis property XAxisLocation and YAxisLocation being set to origin.
In other words,
x = linspace(-5,5);
y = sin(x);
plot(x,y)
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
Example is taken from MATLAB official documentation:
Display Axis Lines through Origin
Controlling Axis Location
I just can't find it. How to set up axis and labels in matlab so they cross at zero point, with the labels just below the axis not on left/bottom of the plot ?
If I didn't make myself clear - I just want the plot to look like like we all used to draw it when in school. Axes crossing, 4 quadrants, labels right below axis, curve ... as it goes.
Anyone knows how to set it up ?
You should check out two submissions on The MathWorks File Exchange:
PlotAxisAtOrigin by Shanrong Zhang
axescenter by Matt Fig
Hopefully these will work with whatever MATLAB version you have (the submission from Matt Fig is the most recently updated one).
As of Matlab release R2015b, this can be achieved with the axis property XAxisLocation and YAxisLocation being set to origin.
In other words,
x = linspace(-5,5);
y = sin(x);
plot(x,y)
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
Example is taken from MATLAB official documentation:
Display Axis Lines through Origin
Controlling Axis Location