首先,我们需要在 Python 中导入所需的库与模块,并对 notebook 环境与图表风格进行初步的设置:
- %matplotlib inline
- import matplotlib.pyplot as plt
- plt.style.use('seaborn-whitegrid')
- import numpy as np
运用 axes 函数,我们构建了一个空的坐标系,并将坐标轴刻度设置为幂形式:
- ax = plt.axes(xscale='log', yscale='log')
Matplotlib 中的 ticker 模块用于支持坐标轴刻度的修改,调用下列命令可以初步查看主副坐标轴刻度的数值定位方式(locator)与具体格式(formatter):
- print(ax.xaxis.get_major_locator())
- print(ax.xaxis.get_minor_locator())
- print(ax.xaxis.get_major_formatter())
- print(ax.xaxis.get_minor_formatter())
我们可以使用 set_major_locator 和 set_major_formatter 命令来调整坐标轴的刻度,如去除坐标轴的刻度显示:
- ax = plt.axes()
- ax.plot(np.random.rand(50))
- ax.yaxis.set_major_locator(plt.NullLocator())
- ax.xaxis.set_major_formatter(plt.NullFormatter())
以上内容转自 数析学院,只节选了部分,有需要的同学可以直接查看原文


雷达卡




京公网安备 11010802022788号







