#
Log Plots
in
MATLAB^{®}

How to make Log Plots plots in MATLAB^{®} with Plotly.

## Plot One Line

Define `x`

as a vector of 50 logarithmically spaced numbers on the interval [10^{-1},10^{2}]. Define `y`

as 2^{x}. Then plot `x`

and `y`

, and call the `grid`

function to show the grid lines.

```
x = logspace(-1,2);
y = 2.^x;
loglog(x,y)
grid on
fig2plotly(gcf);
```

## Plot Multiple Lines

Create a vector of x-coordinates and two vectors of y-coordinates. Plot two lines by passing comma-separated x-y pairs to `loglog`

.

```
x = logspace(-1,2);
y1 = 10.^x;
y2 = 1./10.^x;
loglog(x,y1,x,y2)
grid on
fig2plotly(gcf);
```

Alternatively, you can create the same plot with one x-y pair by specifying y as a matrix: `loglog(x,[y1;y2])`

.

## Specify Axis Labels and Tick Values

Create a set of x- and y-coordinates and display them in a log-log plot.

```
x = logspace(-1,2,10000);
y = 5 + 3*sin(x);
loglog(x,y)
fig2plotly(gcf);
```

Call the `yticks`

function to position the y-axis tick values at whole number increments along the y-axis. Then create x- and y-axis labels by calling the `xlabel`

and `ylabel`

functions.

```
x = logspace(-1,2,10000);
y = 5 + 3*sin(x);
loglog(x,y)
yticks([3 4 5 6 7])
xlabel('x')
ylabel('5 + 3 sin(x)')
fig2plotly(gcf);
```

## Plot Points as Markers Without Lines

Create a set of x- and y-coordinates and display them in a log-log plot. Specify the line style as `'s'`

to display square 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 = logspace(-1,2,20);
y = 10.^x;
loglog(x,y,'s','MarkerFaceColor',[0 0.447 0.741])
grid on
fig2plotly(gcf);
```

## Add a Legend

Create two sets of x- and y-coordinates and display them in a log-log plot. Display a legend in the upper left corner of the plot by calling the `legend`

function and specifying the location as `'northwest'`

.

```
x = logspace(-1,2,10000);
y1 = 5 + 3*sin(x/4);
y2 = 5 - 3*sin(x/4);
loglog(x,y1,x,y2,'--')
legend('Signal 1','Signal 2','Location','northwest')
fig2plotly(gcf);
```