调整坐标轴的刻度(locator

    xiaoxiao2021-12-14  20

    在python中,可以使用locator_params进行对坐标轴刻度的调整,通过nbins设置坐标轴一共平均分为几份,也可以显式的指定要调整的坐标轴,可以通过面向对象的方式或者是pyplot的方式,pyplot的方式更简单。

    #!/usr/bin/python #coding: utf-8 import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 10, 1) plt.plot(x, x) # 获取当前的坐标轴 ax = plt.gca() # 设置把x轴和y轴都平均分成20份 # ax.locator_params(nbins = 20) # 指定需要设置的x轴或y轴的刻度 # ax.locator_params("x", nbins = 20) # 设置y轴 ax.locator_params("y", nbins = 5) # 上面是采用面向对象的方式运行的,如果要在交互式窗口进行对坐标轴进行修改并不能成功 # 下面是采用pyplot的方式 plt.locator_params("x", nbins = 5) plt.show()

    转载请注明原文地址: https://ju.6miu.com/read-971214.html

    最新回复(0)