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.

In this question it is answered how to add a vertical line to a graph. However, it has not been shown that how can someone add the position of that vertical line to the axis. How can I add the coordinate of a vertical line to the graph itself? I want to be able to change the font size of the coordinate too. By using the code below I can change the font size of the coordinate of axes. I want similar thing for the solution to this question too.

FrameStyle -> Directive[Black, Bold, 80]

Here is an example:

line3 = Line[{{2.33, -2}, {2.33, 2}}];
Plot[Sin[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Red}, Frame -> True, FrameStyle ->Directive[Thick, Bold, 20], Epilog -> {Directive[Thick, Blue], line3}]

Result: enter image description here

share|improve this question
    
Can you provide the code for the Plot as well? And where you want your vertical line. –  Öskå Jun 17 at 10:48
    
@Öskå. I added more details. –  yashar Jun 17 at 10:54
    
FrameTicks -> {{0, 1, 2.33, 3, 4, 5, 6}, Automatic}? –  Pickett Jun 17 at 11:00
    
Where should be the position of the vertical line located? I have this but it's ugly since everything is so huge. –  Öskå Jun 17 at 11:01
    
@Öskå. The position is not that much important. In this example I placed the vertical line at 2.33. –  yashar Jun 17 at 11:03

2 Answers 2

up vote 5 down vote accepted

The easiest way to accomplish this is to change the ticks (with FrameTicks) on the axes manually.

FrameTicks -> {{Automatic, Automatic}, {{0, 1, 2.33, 3, 4, 5, 6}, None}}

If you have a large number of ticks on your axes writing them down like this could be cumbersome, in which case you could try to generate the range and then replace another tick with the new tick or insert the extra tick that you want, like this:

{{Automatic, Automatic}, {Range[6] /. 2 -> 2.33, None}}

or

{{Automatic, Automatic}, {Insert[Range[6], 2.33, 3], None}}

Result:

Plot


One can then easily make it automatic (thank you Öskå for this code and animation):

line3[y_] := Line[{{y, -2}, {y, 2}}];
Manipulate[
  Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle -> {Thick, Red}, Frame -> True, 
    FrameStyle -> Directive[Thick, Bold, 20], 
    Epilog -> {Directive[Thick, Blue], line3[t]}, 
    FrameTicks -> {{Automatic, Automatic}, {Range[0, 6] /. Round@t -> t, None}}], {t, 0, 6}]

enter image description here

share|improve this answer
    
I added a more general case based on your idea, I hope you don't mind. If you do feel free to delete it :) –  Öskå Jun 17 at 12:17
    
@Öskå I think it's great, thank you! :) –  Pickett Jun 17 at 18:38
1  
Stop thanking me in public, I'm going to blush ;o) It's just that I was about the post this answer right after you posted yours, so I thought that I would put mine in yours.. :) –  Öskå Jun 17 at 18:41

An answer with GridLines:

Plot[Sin[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Red}, Frame -> True, 
 FrameStyle -> Directive[Thick, Bold, 20], 
 GridLines -> {{2.33}, None}, 
 GridLinesStyle -> Directive[Blue, Thick], 
 Epilog -> Text[Framed[2.33], {2.33, -0.9}, Background -> White]]

enter image description here

Manipulate[
 Plot[Sin[x], {x, 0, 2*Pi}, PlotStyle -> {Thick, Red}, Frame -> True, 
  FrameStyle -> Directive[Thick, Bold, 20], GridLines -> {{m}, None}, 
  GridLinesStyle -> Directive[Blue, Thick], 
  Epilog -> 
   Text[Framed[NumberForm[m, 3]], {m, -0.9}, 
    Background -> White]], {m, 0, 2 Pi}]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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