如何细致的调整ax的坐标轴

131 阅读1分钟

最近有一个需求:需要通过 ax 来设置 plt 中 各个子图的坐标轴的信息。然后找了很久,最后通过文档找到了 ax.tick_params()这个方法,这个里面的可以设置的东西很多。

不过需要注意,这个函数的几个设置只有在几个比较新的版本才有,我用的 3.4.0版本就一直不能设置 labelfontfamily 这个参数。

import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":
    t = np.arange(0.0, 2.0, 0.01)
    s = np.sin(2 * np.pi * t)

    fig, ax = plt.subplots()
    ax.plot(t, s)

    ax.grid(True, linestyle='-.')
    ax.tick_params(labelcolor='b', labelsize='medium', width=3, labelfontfamily='Times New Roman')

    plt.show()

下面在记录原网址 ax.tick_params()