Reputation: 46493
After having plotted some data:
import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.linspace(-3.0, 3.0, 10), np.random.random(10))
plt.plot(np.linspace(0.0, 7.0, 50), np.random.random(50))
plt.show()
I'd like to change the x-axis labels to 0.0 ... 50.0 instead of -4.0 ... 8.0 (but keeping exactly the same plot). Is it possible to do it in one-line?
Upvotes: 2
Views: 688
Reputation: 2822
You can use the following function, and give numerical labels:
import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.linspace(-3.0, 3.0, 10), np.random.random(10))
plt.plot(np.linspace(0.0, 7.0, 50), np.random.random(50))
plt.xticks([-4, -2, 0, 2, 4, 6, 8], ['0', '10', '20', '30', '40', '50'])
Upvotes: 1