Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 175 additions & 1 deletion _posts/matlab/1A-plot-types/line-plots/2020-08-04-plot3.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,182 @@ Z = cos(t);
<pre class="mcode">
plot3(X,Y,Z)

fig2plot()
fig2plotly()
</pre>

{% include posts/mframe.html src="https://plotly.com/~jackp/18782.embed" %}

<!--------------------- EXAMPLE BREAK ------------------------->
## Specify Equally-Spaced Tick Units and Axis Labels

> Create vectors xt, yt, and zt.

<pre class="mcode">
t = 0:pi/500:40*pi;
xt = (3 + cos(sqrt(32)*t)).*cos(t);
yt = sin(sqrt(32) * t);
zt = (3 + cos(sqrt(32)*t)).*sin(t);
</pre>

> Plot the data, and use the axis equal command to space the tick units equally along each axis. Then specify the labels for each axis.

<pre class="mcode">
plot3(xt,yt,zt)
axis equal
xlabel('x(t)')
ylabel('y(t)')
zlabel('z(t)')
fig2plotly()
</pre>

{% include posts/mframe.html src="https://plotly.com/~nouman_tariq/484.embed" %}

<!--------------------- EXAMPLE BREAK ------------------------->
## Plot Points as Markers Without Lines

> Create vectors t, xt, and yt, and plot the points in those vectors using circular markers.

<pre class="mcode">
t = 0:pi/20:10*pi;
xt = sin(t);
yt = cos(t);
plot3(xt,yt,t,'o')
fig2plotly()
</pre>

{% include posts/mframe.html src="" %}


<!--------------------- EXAMPLE BREAK ------------------------->
## Customize Color and Marker

> Create vectors t, xt, and yt, and plot the points in those vectors as a blue line with 10-point circular markers. Use a hexadecimal color code to specify a light blue fill color for the markers.

<pre class="mcode">
t = 0:pi/20:10*pi;
xt = sin(t);
yt = cos(t);
plot3(xt,yt,t,'-o','Color','b','MarkerSize',10,'MarkerFaceColor','#D9FFFF')
fig2plotly()
</pre>

{% include posts/mframe.html src="" %}

<!--------------------- EXAMPLE BREAK ------------------------->
## Specify Line Style

> Create vector t. Then use t to calculate two sets of x and y values.


<pre class="mcode">
t = 0:pi/20:10*pi;
xt1 = sin(t);
yt1 = cos(t);

xt2 = sin(2*t);
yt2 = cos(2*t);
</pre>

> Plot the two sets of values. Use the default line for the first set, and specify a dashed line for the second set.

<pre class="mcode">
plot3(xt1,yt1,t,xt2,yt2,t,'--')
fig2plotly()
</pre>

{% include posts/mframe.html src="" %}

<!--------------------- EXAMPLE BREAK ------------------------->
## Modify Line After Plotting

> Create vectors t, xt, and yt, and plot the data in those vectors. Return the chart line in the output variable p.


<pre class="mcode">
t = linspace(-10,10,1000);
xt = exp(-t./10).*sin(5*t);
yt = exp(-t./10).*cos(5*t);
p = plot3(xt,yt,t);
</pre>

> Change the line width to 3.

<pre class="mcode">
p.LineWidth = 3;
fig2plotly()
</pre>

{% include posts/mframe.html src="https://plotly.com/~nouman_tariq/492.embed" %}

<!--------------------- EXAMPLE BREAK ------------------------->
## Specify Target Axes

> Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 1-by-2 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Create separate line plots in the axes by specifying the axes object as the first argument to plot3.

<pre class="mcode">
tiledlayout(1,2)

% Left plot
ax1 = nexttile;
t = 0:pi/20:10*pi;
xt1 = sin(t);
yt1 = cos(t);
plot3(ax1,xt1,yt1,t)
title(ax1,'Helix With 5 Turns')

% Right plot
ax2 = nexttile;
t = 0:pi/20:10*pi;
xt2 = sin(2*t);
yt2 = cos(2*t);
plot3(ax2,xt2,yt2,t)
title(ax2,'Helix With 10 Turns')
fig2plotly()
</pre>

{% include posts/mframe.html src="" %}


<!--------------------- EXAMPLE BREAK ------------------------->
## Plot Duration Data with Custom Tick Format

> Create x and y as vectors of random values between 0 and 1. Create z as a vector of random duration values.

<pre class="mcode">
x = rand(1,10);
y = rand(1,10);
z = duration(rand(10,1),randi(60,10,1),randi(60,10,1));
</pre>

> Plot x, y, and z, and specify the format for the z-axis as minutes and seconds. Then add axis labels, and turn on the grid to make it easier to visualize the points within the plot box.

<pre class="mcode">
plot3(x,y,z,'o','DurationTickFormat','mm:ss')
xlabel('X')
ylabel('Y')
zlabel('Duration')
grid on
fig2plotly()
</pre>

{% include posts/mframe.html src="" %}


<!--------------------- EXAMPLE BREAK ------------------------->
## Plot Line With Marker at One Data Point

> Create vectors xt, yt, and zt. Plot the values, specifying a solid line with circular markers using the LineSpec argument. Specify the MarkerIndices property to place one marker at the 200th data point.

<pre class="mcode">
t = 0:pi/500:pi;
xt(1,:) = sin(t).*cos(10*t);
yt(1,:) = sin(t).*sin(10*t);
zt = cos(t);
plot3(xt,yt,zt,'-o','MarkerIndices',200)
fig2plotly()
</pre>

{% include posts/mframe.html src="" %}