Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

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.

    
check out GridLines with some of the examples of gridlines with specific values. –  Mike Honeychurch Dec 7 '12 at 5:16
    
Thanks! I'll try. –  Lei Chen Dec 7 '12 at 5:19
    
@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? –  halirutan Dec 7 '12 at 5:30
    
@halirutan I just want multiple horizontal lines. How to plot Function with grid is well explained by the documentation center. Thanks! –  Lei Chen Dec 7 '12 at 5:35
    
Drawing lines is also pretty well covered in the manual. What was the problem you faced there? –  Sjoerd C. de Vries Dec 7 '12 at 6:59
add comment

2 Answers

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

share|improve this answer
    
Thanks!! You just solved something I wasn't able to figure out a whole night! –  Lei Chen Dec 7 '12 at 5:44
    
@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! –  halirutan Dec 7 '12 at 5:47
    
even that is easier to do with gridLines -- Graphics[{}, GridLines -> {None, {-1, 0, 1}}] –  Mike Honeychurch Dec 7 '12 at 5:51
add comment

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

share|improve this answer
    
Why not just Plot[{-1, 0, 1}, ...]? –  Rahul Narain Dec 7 '12 at 15:57
    
:) I was trying to get as close to the question as possible... –  cormullion Dec 7 '12 at 16:07
add comment

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