简体   繁体   中英

Changing axis ticks in matplotlib

I am trying to space out the last Portion of the following plot in such a way, that the x axis scaling changes in step size. I would like to achieve a plot, weher the distance between 5 and 5.1 is equal to the distance between lets say 2 and 3.

I am Aware that this would alter the slope of the plot. Yet I would like to Focus on a specific area, in this case the range between 5 and 5.2, but would like to retain the rest of the plot in a different step size.

Is this at all possible?

x = [1, 2, 3, 4, 5, 5.1, 5.2]
y = [1, 4, 9, 6, 2, 5, 6]
xt = [1, 2, 3, 4, 5, 5.1, 5.2]
plt.xticks(x,xt)
plt.plot(x,y)
plt.show()

在此处输入图片说明

You'd need to change the x values, and then alter the labels:

x = [1, 2, 3, 4, 5, 6, 7]
y = [1, 4, 9, 6, 2, 5, 6]
labels = [1, 2, 3, 4, 5, 5.1, 5.2]
plt.plot(x, y)
plt.xticks(x, labels)
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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM