Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting horizontal and vertical lines in Mathematica

In Mathematica, how do you plot a horizontal line at a given number? How do you plot a vertical line at a given number?

like image 275
karlsbad Avatar asked May 24 '10 13:05

karlsbad


People also ask

Can you graph in Mathematica?

In addition to being a powerful programming tool, Mathematica allows a wide array of plotting and graphing options.

How do you remove a horizontal line in Mathematica?

If the line is at the same height as an edge of the right bracket of a cell, then select this cell, go to menu Insert > Horizontal Line > None or uncheck the box.

What is plotting in Mathematica?

Plot is known as a function plot or graph of a function. Plot evaluates f at values of x in the domain being plotted over, and connects the points {x,f[x]} to form a curve showing how f varies with x.

How do you add text to a plot in Mathematica?

You can also add text to a graphic by using the text tool. Select the text tool, click a graphic, and then enter some text: In the graphic below, the math tool was used to enter the plotted function, . The text description of the plot was entered using the text tool.


1 Answers

If you're actually using Plot (or ListPlot, et c.), the easiest solution is to use the GridLines option, which lets you specify the x- and y-values where you want the lines drawn. For instance:

Plot[Sin[x], {x, 0, 2 \[Pi]},   GridLines -> {{0, \[Pi]/2, \[Pi], 3 \[Pi]/2, 2 \[Pi]},                 {-1, -Sqrt[3]/2, -1/2, 0, 1/2, Sqrt[3]/2, 1}}] 

many lines

EDIT to add:

Of course, this solution works if you just want to draw a line at a single, given number. For instance, if you want to reproduce the second example from dreeve's answer:

Plot[Sin[x], {x, 0, 2 Pi},  GridLines -> {{4}, {}}] 

one line

like image 104
Pillsy Avatar answered Sep 19 '22 19:09

Pillsy