python matplotlib notes: grid lines

Tick ​​mark positioning and formatting
This module contains classes for configuring tick mark positioning and formatting. Generic tick locators and formatters are provided, as well as domain-specific custom tick locators and formatters.
Although these locators know nothing about major or minor tick marks, they are used by the Axis class to support positioning and formatting of major and minor tick marks.
The Locator class is the base class for all tick mark locators. The locator handles automatic scaling of view limits based on data constraints, and selection of tick locations. A useful semi-automatic tick locator is MultipleLocator. It is initialized with a base (e.g. 10) and selects axis limits and scales that are multiples of that base.
1. Parameter
AutoLocator: MaxNLocator with simple default value. This is the default tick mark locator for most plots.
MaxNLocator: Finds the maximum number of intervals and scales them at the appropriate location.
LinearLocator: Evenly space tick marks from minimum value to maximum value
LogLocator: Logarithmically space the tick marks from minimum value to maximum value.
MultipleLocator: Scale and range are multiples of the base; can be integers or floating point numbers.
FixedLocator: The scale position is fixed.
IndexLocator: Locator for the index map (for example, x = range(len(y))).
NullLocator: Null locator, no scale
SymmetricalLogLocator: Locator used with symlog specifications; for parts outside the threshold, the working principle is similar to LogLocator, if it is within the threshold, 0 is added.
AsinhLocator: Locator for asinh specifications that attempts to approximately evenly space tick marks.
LogitLocator: Locator for logarithmic scaling
AutoMinorLocator: Minor tick locator when the axes are linear and the major ticks are evenly spaced. Subdivides major tick intervals into a specified number of minor tick intervals, defaults to 4 or 5, depending on major tick intervals.

2. Sample

ax.xaxis.set_major_locator(plt.AutoLocator)
# ax.xaxis.set_minor_locator()
ax.yaxis.set_major_locator(plt.AutoLocator)
# ax.yaxis.set_minor_locator()

3. Reference documentation
matplotlib official website

Guess you like

Origin blog.csdn.net/weixin_39747882/article/details/128436702