Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot vertical line in octave?

What it the best way to plot a vertical line using Octave?

like image 421
Austin A Avatar asked Sep 07 '14 02:09

Austin A


People also ask

How do you plot a vertical line in Octave?

Instead use the line() function, to draw on top of your plot. The line() function require 2 non-standard x-values and y-values vectors, instead of the standard point-slope arguments for point A and point B , normally represented by (x1,y1) and (x2,y2) . Instead, you need to write this as: X=(x1,x2) and Y=(y1,y2) .

How do I plot a vertical line in Matlab?

xline( x ) creates a vertical line at one or more x-coordinates in the current axes. For example, xline(2) creates a line at x=2 . xline( x , LineSpec ) specifies the line style, the line color, or both. For example, xline([12 20 33],'--b') creates three dashed blue lines.

How do you plot a graph in Octave?

The plotyy function may be used to create a plot with two independent y axes. Plot two sets of data with independent y-axes and a common x-axis. The arguments x1 and y1 define the arguments for the first plot and x1 and y2 for the second. By default the arguments are evaluated with feval (@plot, x , y ) .


1 Answers

So, I have two methods for this. One, I found, and the other I made up.

Method 1: From here.

%% Set x value where verticle line should intersect the x-axis.
x = 0;
%% plot a line between two points using plot([x1,x2],[y1,y2])
plot([x,x],[-10,10]);

Method 2: A slightly different approach, exact same result

%% Setup a vector of x values
x = linspace(0,0,100);
%% Setup a vector of y values
y = linspace(0,10,100);
%% Plot the paired points in a line
plot(x,y);

I think Method 2 may write more information to memory before the plot process and it's a line longer, so in my eyes, Method 1 should be the better option. If you prefer Method 2, make sure your x and y vectors are the same dimension or you'll end up with a bunch of dots where you're line should be.

like image 71
Austin A Avatar answered Oct 06 '22 12:10

Austin A