In Mathematica, how do you plot a horizontal line at a given number? How do you plot a vertical line at a given number?
In addition to being a powerful programming tool, Mathematica allows a wide array of plotting and graphing options.
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.
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.
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.
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}}]
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}, {}}]
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