1.在python中使用matplotlib画图,默认横坐标都是由小到大(1,2,3,4,5),但我现在项目特殊需求,想让横坐标值由大到小逆序显示(5,4,3,2,1),如何实现呢?
import matplotlib.pyplot as plt
xlist = [1, 2, 3, 4, 5]
ylist = [10, 20, 30, 40, 50]
plt.scatter(xlist,ylist)
#plt.gca().invert_xaxis()
plt.show()
结果
X坐标轴从大到小
import matplotlib.pyplot as plt
xlist = [1, 2, 3, 4, 5]
ylist = [10, 20, 30, 40, 50]
plt.scatter(xlist,ylist)
plt.gca().invert_xaxis()
plt.show()
结果