1

I was trying to plot a vertical line with markers on it using ax.axvline but the markers only show up on the bottom and top of the figure. I have played around with the markevery kwarg but it does not seem to have any effect when I change it even though it works for a normal line plot. Does anyone know if this is because no discrete values are specified along the axis or am I just doing something wrong?

I realize that I can plot a vertical line on my own and specify the markers, but I figure given the purpose of axvline I should use it.

Here is an example code of what I am talking about:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-10,10)
y = x**2-15.


fig = plt.figure(figsize=(4,4))
ax = plt.subplot(111)

ax.plot(y,x) #Test curve

ax.plot(2+np.zeros(len(x)),x,marker='X',markevery=1) #another way to plot what I want.

ax.axvline(0,c='r',marker='X',markevery=1) #markerevery doesn't seem to work

plt.show()

enter image description here

2
  • 3
    The axvline consists of only two points, the start and the end. So you cannot mark any points that aren't there. Apr 18, 2019 at 20:16
  • Thats what I suspected, thanks for the confirmation.
    – BenT
    Apr 18, 2019 at 20:24

1 Answer 1

1

As mentioned by ImportanceofBeingErnest, the markereverykwarg does not apply for axvline or axhline because there are technically only 2 points used to draw the line at the boundaries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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