简体   繁体   中英

matplotlib ticks overlapping with pre-existing ones

I am attempting to define ticks for a log scale axis, and a strange bug I am finding is that, on one axis only, the previous default ticks are not removed, and so my new custom ticks overlap them. But only on the y-axis.

plt.figure()
plt.scatter(np.linspace(15, 190), np.linspace(55, 310))
plt.xscale("log")
plt.xticks([2e1, 4e1, 6e1, 1e2, 2e2], [20, 40, 60, 100, 200])
plt.yscale("log")
plt.yticks([6e1, 1e2, 2e2, 3e2], [60, 100, 200, 300])
plt.show()

I believe I have treated the x axis and y axis identically, yet this method works for the x axis and the bug is evident on the y axis.

Thank you for advice in advance.

结果图像在这里

I tested your code and it runs perfectly like this:

截屏

  • Matplotlib version: 3.2.1
  • Python version: 3.7.7

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