3

I have the following code:

import matplotlib.pyplot as plt
x=0
xval=[]
yval=[]
for i in range(0,1000):
    x=i
    xval.append(x)
    y=1-(0.99**x)
    yval.append(y)
plt.axhline(0.5, color='r')
plt.axvline(69, color='r')
plt.plot(xval,yval)
plt.show()

I want to highlight the 69 on the x-axis like this: example

Does anyone know how to show a specific x value on the axis?

1
  • I swear it isn't intentional! Commented Feb 22, 2022 at 18:47

1 Answer 1

3

You can use xticks:

import matplotlib.pyplot as plt
x=0
xval=[]
yval=[]
for i in range(0,1000):
    x=i
    xval.append(x)
    y=1-(0.99**x)
    yval.append(y)
plt.axhline(0.5, color='r')
plt.axvline(69, color='r')
plt.plot(xval,yval)
plt.xticks([69],["Nice"])
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to make it show aswell as the default ticks?
plt.xticks([69]+range(0,1000,200),["Nice"]+range(0,1000,200))

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.