Bilal
Bilal

Reputation: 3272

Replace x axis values

Let's say I have this code :

nbrs = np.array([0, 13, 13, 7, -9, 0])
x_values = np.array([0, 50, 100, 150, 200, 250])
plt.plot(nbrs)
plt.xticks(my_xticks)

enter image description here

When I tried xticks it doesn't work :

nbrs = np.array([0, 13, 13, 7, -9, 0])
x_values = np.array([0, 50, 100, 150, 200, 250])
plt.plot(nbrs)
plt.xticks(my_xticks)

enter image description here

Instead of [1, 2, 3, 4, 5] I want to have [0, 50, 100, 150, 200, 250].

Upvotes: 1

Views: 2049

Answers (2)

Joooeey
Joooeey

Reputation: 3866

You should pass your x-values to the plt.plot function. No need to use plt.xticks. Like this:

import numpy as np
import matplotlib.pyplot as plt

nbrs = np.array([0, 13, 13, 7, -9, 0])
x_values = np.array([0, 50, 100, 150, 200, 250])
plt.plot(x_values,nbrs)

console output

Upvotes: 0

Binyamin Even
Binyamin Even

Reputation: 3382

simply:

plt.plot(x_values,nbrs)

Upvotes: 1

Related Questions