Skip to content
Related Articles

Related Articles

Improve Article
Matplotlib.pyplot.tick_params() in Python
  • Last Updated : 19 Apr, 2020

Matplotlib is a visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.


matplotlib.pyplot.tick_params() is used to change the appearance of ticks, tick labels, and gridlines.


matplotlib.pyplot.tick_params(axis='both', **kwargs)

Parameters :

axis{‘x’, ‘y’, ‘both’}, optionalWhich axis to apply the parameters to. Default is ‘both’.
resetbool, default: FalseIf True, set all parameters to defaults before processing other keyword arguments..
which{‘major’, ‘minor’, ‘both’}Default is ‘major’; apply arguments to which ticks.
direction{‘in’, ‘out’, ‘inout’}Puts ticks inside the axes, outside the axes, or both.
lengthfloatTick length in points.
widthfloatDefault is ‘major’; apply arguments to which ticks.
colorcolorTick color.
padfloatDistance in points between tick and label.labelsizefloat or strTick label font size in points or as a string (e.g., ‘large’).labelcolorcolorTick label color.colorscolorTick color and label color.zorderfloatTick and label zorder.bottom, top, left, rightboolWhether to draw the respective ticks.labelbottom, labeltop, labelleft, labelrightboolWhether to draw the respective tick labels.labelrotationfloatTick label rotationgrid_colorcolorGridline colorgrid_alphafloatTransparency of gridlines: 0 (transparent) to 1 (opaque).grid_linewidthfloatWidth of gridlines in points.grid_linestylestrAny valid Line2D line style spec.

Example #1: Default plot

# importing libraries
import matplotlib.pyplot as plt 
# values of x and y axes 
x = [i for i in range(5, 55, 5)]
y = [1, 4, 3, 2, 7, 6, 9, 8, 10, 5
plt.plot(x, y) 

Output :

Example #2:

# importing libraries
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, ScalarFormatter
fig, ax = plt.subplots()
ax.plot([0, 10, 20, 30], [0, 2, 1, 2])
ax.tick_params(axis ='both', which ='major'
               labelsize = 16, pad = 12
               colors ='r')
ax.tick_params(axis ='both', which ='minor',
               labelsize = 8, colors ='b')


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :