Matplotlib is an amazing 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. It was introduced by John Hunter in the year 2003.
One of the greatest benefits of visualization is that it allows us visual access to huge amounts of data in easily digestible visuals. Matplotlib consists of several plots like line, bar, scatter, histogram etc.
Ticks are the values used to show specific points on the coordinate axis. It can be a number or a string. Whenever we plot a graph, the axes adjust and take the default ticks. Matplotlib’s default ticks are generally sufficient in common situations but are in no way optimal for every plot. Here, we will see how to customize these ticks as per our need.
|axis||x, y, both||Tells which axis to operate|
|reset||True, False||If True, set all parameters to default|
|direction||in, out, inout||Puts the ticks inside or outside or both|
|length||Float||Sets tick’s length|
|width||Float||Sets tick’s width|
|rotation||Float||Rotates ticks wrt the axis|
|colors||Color||Changes tick color|
|pad||Float||Distance in points between tick and label|
Example #1: Default plot
Example #2: Playing with the ticks
Suppose we don’t want to display the values of ticks or want our ticks to be tilted or want any other customization. We can do it this way.
Example #3: Changing the values of ticks.
In the first example, the x-axis and y-axis were divided by the value of 10 and 2 respectively. Let’s make it 5 and 1.
The main difference from the 1st example is :
plt.xticks(np.arange(0, 51, 5))
plt.yticks(np.arange(0, 11, 1))
Changing the values in np.arange will change the range of ticks.
Reference: Matplotlib ticks.
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.
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
- twitter-text-python (ttp) module - Python
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python program to check if the list contains three consecutive common numbers in Python
- Creating and updating PowerPoint Presentations in Python using python - pptx
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : yogesh_pandey