semilogyCreate a vector of x-coordinates and a vector of y-coordinates. Create a log-linear plot of
xandy, and call thegridfunction to show the grid lines.
x = 1:100; y = x.^2; semilogy(x,y) grid on fig2plotly()
Create a vector of x-coordinates and two vectors of y-coordinates. Plot two lines by passing comma-separated x-y pairs to
semilogy.
x = 1:100; y1 = x.^2; y2 = x.^3; semilogy(x,y1,x,y2) grid on fig2plotly()
Define vector
xas the installments on a 20 year loan. Define vectoryas the cumulative cost of a $1000 loan with an interest rate of 8%. Plot the cumulative cost at each installment.
P = 1000; npayments = 240; rate = 0.08/12; mpayment = P*(rate*(1+rate)^npayments)/(((1+rate)^npayments) - 1); x = 1:240; y = x * mpayment; semilogy(x,y); grid on fig2plotly()
Change the y-axis tick values and tick labels by calling the
yticksandyticklabelsfunctions. Then create x- and y-axis labels by calling thexlabelandylabelfunctions.
yticks([10 50 100 500 1000])
yticklabels({'$10','$50','$100','$500','$1000'})
xlabel ('Installment')
ylabel('Cumulate Cost')
Create a set of x- and y-coordinates and plot them in a log-linear plot. Specify the line style as
'o'to display circular markers without connecting lines. Specify the marker fill color as the RGB triplet[0 0.447 0.741], which corresponds to a dark shade of blue.
x = linspace(1,1000,15); y = (1./x) * 10000; semilogy(x,y,'o','MarkerFaceColor',[0 0.447 0.741]) grid on fig2plotly()
Create two sets of x- and y-coordinates and display them in a log-linear plot. Specify a dashed line for the first set of coordinates. Then display a legend in the upper left corner of the plot by calling the
legendfunction and specifying the location as'northwest'.
x = 1:100;
y1 = x.^2;
y2 = x.^3;
semilogy(x,y1,'--',x,y2)
legend('x^2','x^3','Location','northwest')
fig2plotly()
When you specify only one coordinate vector,
semilogyplots those coordinates against the values1:length(y). For example, defineyas a vector of 5 values. Create a log-linear plot of y.
y = [0.1 0.2 1 10 1000]; semilogy(y) grid on fig2plotly()
If you specify
yas a matrix, the columns of y are plotted against the values1:size(y,1). For example, defineyas a 5-by-3 matrix and pass it to thesemilogyfunction. The resulting plot contains 3 lines, each of which has x-coordinates that range from1to5.
y = [ 0.1 1 10
0.2 2 20
1.0 10 100
10 100 1000
1000 10000 100000];
semilogy(y)
grid on
fig2plotly()
Create a tiled chart layout in the
'flow'tile arrangement, so that the axes fill the available space in the layout. Next, call thenexttilefunction to create an axes object and return it asax1. Then display a log-linear plot by passingax1to thesemilogyfunction.
tiledlayout('flow')
ax1 = nexttile;
x = 1:100;
y1 = x.^2;
semilogy(ax1,x,y1)
fig2plotly()
Repeat the process to create a second log-linear plot.
ax2 = nexttile; y2 = 1./x; semilogy(ax2,x,y2) fig2plotly()
Create a log-linear plot containing two lines, and return the line objects in the variable
slg.
x = 1:100; y1 = x.^2; y2 = x.^3; slg = semilogy(x,y1,x,y2); fig2plotly()
Change the width of the first line to
3, and change the color of the second line to purple.
slg(1).LineWidth = 3; slg(2).Color = [0.4 0 1]; fig2plotly()
Insert
NaNvalues wherever there are discontinuities in your data. Thesemilogyfunction displays gaps at those locations.Create a pair of x- and y-coordinate vectors. Replace the twentieth y-coordinate with a
NaNvalue. Then create a log-linear plot ofxandy.
x = 1:50; y = x.^2; y(20) = NaN; semilogy(x,y) fig2plotly()