0

I want to plot a vertical line in my matplotlib loglog plot, but they line never shows up. I tried two methods and both fail. How do I do it?

So toy example:

import numpy as np
import matplotlib.pyplot as plt

N = 1000
r= np.random.randn(N)
x = np.exp(0.01 * np.arange(N)) +0.2
y = np.exp(0.4 * (np.arange(N)+r))
plt.loglog(x,y,label="Hello ")

So the above works (except that the legend doesnt show up, so if you know how to solve that bonus points).

But now when I try to add a vertical line:

plt.axvline(x=1.2, color='g')

it doesn't appear. Neither does the following trick work:

ylim = plt.get_ylim()
plot.plot([1.2, 1.2], ylim, 'r--')

What can I do?

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
  • 1
    It works for me (and it should). Are you sure it's not just invisible because it's at the root (x=1.2 small compared to the rest)? Maybe show your output. Because of syntax-errors (py3); i needed to change your code and i see the vertical line. Try my code [here](https://gist.github.com/sschnug/90c643d1109556fc13052bb6f627ffd8). – sascha Sep 30 '16 at 14:06
  • 1
    *Syntax errors* might have been a wrong desciption. The multiplication within np.exp did not work for me, so i changed the range option to use numpy's range. – sascha Sep 30 '16 at 14:17
  • Thanks ... interesting, so I just tried your code and it works for me too ... so I am very confused why it doesnt work with my actual data ... there must be some other problem. – patapouf_ai Sep 30 '16 at 14:17
  • Thanks for also for helping me plot the legend. – patapouf_ai Sep 30 '16 at 14:20
  • Ok yes! You were right! It now works also with my actual data. It was just some syntax errors. So what should I do with this question? should I delete it? – patapouf_ai Sep 30 '16 at 14:29
  • @sascha, now I have another problem though that the lines are not in the right location ... I made another question for that: http://stackoverflow.com/questions/39827697/vertical-line-axvline-plots-line-in-wrong-position-in-loglog-plot-in-matplotlib – patapouf_ai Oct 03 '16 at 08:51

0 Answers0