I'm trying do plot some data with the x axis showing equidistant spacing between the data points.
The code:
#!/usr/bin/env python
from matplotlib import pyplot as plt
sizes = [1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700]
prices = [245, 312, 279, 308, 199, 219, 405, 324, 319, 255]
plt.xlim([1000, 2500])
plt.ylim([0, 500])
plt.xlabel("sizes")
plt.ylabel("prices")
plt.scatter(sizes, prices)
plt.show()
How it looks: How I want it to look:
So the distance between each two neighboring points is equal.
So, it seems your graph is just for representation purpose. The numbers on the x-axis do not need to be on a scale. To plot this, you must create a x
axis list which is actually to scale and just replace its labels by the elements of your sizes
list. The following code shows how to do this
#!/usr/bin/env python
from matplotlib import pyplot as plt
sizes = [1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700]
prices = [245, 312, 279, 308, 199, 219, 405, 324, 319, 255]
plt.ylim([0, 500])
plt.xlabel("sizes")
plt.ylabel("prices")
x = [a for a in range(len(sizes))]
plt.scatter(x,prices)
plt.xticks(x, sizes)
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.