1
$\begingroup$

Possible Duplicate:
How to insert guide-lines in graphics without specifying range?

How to plot multiple horizontal lines?

For instance, I want to plot 3 horizontal lines: y=-1, y=0 and y=1. Seems to be a pretty simple thing, but I couldn't figure out how; although I've searched all over the documentation center.

$\endgroup$

marked as duplicate by Artes, Mr.Wizard Dec 7 '12 at 10:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ check out GridLines with some of the examples of gridlines with specific values. $\endgroup$ – Mike Honeychurch Dec 7 '12 at 5:16
  • $\begingroup$ @LeiChen Can you add more detail to your question? Do you want a graphic only with lines or do you want the lines in a e.g. plot of a function as grid? $\endgroup$ – halirutan Dec 7 '12 at 5:30
  • $\begingroup$ @halirutan I just want multiple horizontal lines. How to plot Function with grid is well explained by the documentation center. Thanks! $\endgroup$ – Lei Chen Dec 7 '12 at 5:35
  • $\begingroup$ Drawing lines is also pretty well covered in the manual. What was the problem you faced there? $\endgroup$ – Sjoerd C. de Vries Dec 7 '12 at 6:59
1
$\begingroup$

If you just want to draw Lines, than you can create your own Graphics. I hope the code is self-explanatory

Graphics[{
  Line[{{0, -1}, {1, -1}}],
  Line[{{0, 0}, {1, 0}}],
  Line[{{0, 1}, {1, 1}}]
}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thanks!! You just solved something I wasn't able to figure out a whole night! $\endgroup$ – Lei Chen Dec 7 '12 at 5:44
  • $\begingroup$ @LeiChen Then please take some minutes to read the FAQ. Especially, you should understand that we have a voting system here and the -1 infront of your question means in your case: "your question is not explained in detail so that it is not clear what you mean". You can always edit your question and you should learn what up/downvoting and accepting is! $\endgroup$ – halirutan Dec 7 '12 at 5:47
  • $\begingroup$ even that is easier to do with gridLines -- Graphics[{}, GridLines -> {None, {-1, 0, 1}}] $\endgroup$ – Mike Honeychurch Dec 7 '12 at 5:51
1
$\begingroup$

The long way round:

Plot[
 {
  Evaluate[y = -1],
  Evaluate[y = 0],
  Evaluate[y = 1]
 }, {x, -10, 10}, PlotStyle -> {Thick}, PlotRange -> {-10, 10}]

the plot thickens

$\endgroup$
  • 1
    $\begingroup$ Why not just Plot[{-1, 0, 1}, ...]? $\endgroup$ – Rahul Dec 7 '12 at 15:57
  • $\begingroup$ :) I was trying to get as close to the question as possible... $\endgroup$ – cormullion Dec 7 '12 at 16:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.