What it the best way to plot a vertical line using 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) .
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.
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 ) .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With