matplotlib set own axis values

6.1k views Asked by At

I have points x = [1000, 15000, 28000, 70000, 850000] y = [10000, 20000, 30000, 10000, 50000] and I get this graphic enter image description here

How can I set my own values on x axis?

Example : 1000, 15000, 28000, 70000, 850000

I Wanna get like this: enter image description here

1

There are 1 answers

0
Ffisegydd On BEST ANSWER

Based on your graphic, you actually want the points to be spaced equally in x and then to set the equally spaced ticks as your custom x array.

The code below will plot them equally (it actually plots them at [0, 1, 2, 3, ...]). It then places ticks at the positions (0, 1, 2, 3,...) with the values given by x using the plt.xticks function.

import matplotlib.pyplot as plt

x = [1000,  15000, 28000, 70000, 850000]
y = [10000, 20000, 30000, 10000, 50000]

x_plot = range(len(y))

plt.plot(x_plot, y)

plt.xticks(x_plot, x)

plt.show()

Plot