- Matplotlib Basics
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - What are Fonts?
- Setting Font Properties Globally
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - Linear and Logarthmic Scales
- Matplotlib - Symmetrical Logarithmic and Logit Scales
- Matplotlib - LaTeX
- Matplotlib - What is LaTeX?
- Matplotlib - LaTeX for Mathematical Expressions
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Enabling LaTex Rendering in Annotations
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib Event Handling
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Plotting
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Violin Plot
- Matplotlib - Contour Plot
- Matplotlib - 3D Plotting
- Matplotlib - 3D Contours
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - Quiver Plot
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - Radian Ticks
A radian is a unit of angular measure used to express angles in mathematics and physics. Ticks, in the field of data visualization, refer to the small lines or marks indicating the scale of the axes.
Radian Ticks in Matplotlib
In the context of Matplotlib, radian ticks typically denote the ticks or markers on an axis that represent values in radians. When dealing with circular or angular data, it is common to use radian ticks on the axis to indicate specific angles. Setting radian ticks involves placing tick marks at specific intervals corresponding to certain radian values on the axis.
Here is a reference image illustrating Radian ticks on a plot −
In the image, you can observe that radian ticks represent the angles of the sine wave along the x-axis.
Radian Ticks for the x axis
Setting Radian Ticks for the x-axis involves using two key methods which are axes.set_xticks() and axes.set_xticklabels(). These methods are allowing you to specify the positions and labels of ticks on the x-axis, respectively.
In addition to these methods, the FormatStrFormatter and MultipleLocator classes from the matplotlib.ticker module can be used to enhance the customization of tick positions and labels.
Example 1
The following example demonstrates how to create a plot with custom radian ticks.
import matplotlib.pyplot as plt import numpy as np # Create plot fig, ax = plt.subplots(figsize=(7, 4)) # Sample data theta = np.linspace(0, 2 * np.pi, 100) y = np.sin(theta) # Plotting the data plt.plot(theta, y) plt.title('Sine Wave') plt.xlabel('Angle (radians)') plt.ylabel('Y-axis') # Custom radian ticks and tick labels custom_ticks = [0, np.pi/2, np.pi, (3*np.pi)/2, 2*np.pi] custom_tick_labels = ['$0$', '$\pi/2$', '$\pi$', '$3\pi/2$', '$2\pi$'] ax.set_xticks(custom_ticks) ax.set_xticklabels(custom_tick_labels) plt.grid(axis='x') # Display the plot plt.show()
Output
On executing the above code we will get the following output −
Example 2
This example uses the FormatStrFormatter and MultipleLocator classes from the matplotlib.ticker module to control the format and positions of ticks.
import matplotlib.pyplot as plt import matplotlib.ticker as tck import numpy as np # Create Plot f,ax=plt.subplots(figsize=(7,4)) # Sample Data x=np.linspace(0, 2 * np.pi, 100) y=np.sin(x) # Plot the sine wave ax.plot(x/np.pi,y) # Customizing X-axis Ticks ax.xaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$')) ax.xaxis.set_major_locator(tck.MultipleLocator(base=1.0)) # Set the titles plt.title('Sine Wave') plt.xlabel('Angle (radians)') plt.ylabel('Y-axis') plt.grid() plt.show()
Output
On executing the above code we will get the following output −
Radian Ticks for the y axis
Similar to the x-axis, setting radian ticks for the y-axis can be done by using the ax.set_yticks() and ax.set_yticklabels() methods. These methods allow you to define the positions and labels of ticks on the y-axis. Additionally, the FormatStrFormatter and MultipleLocator classes from the matplotlib.ticker module can also used.
Example
This example demonstrates how to set customized radian ticks for the y-axis. using the FormatStrFormatter and MultipleLocator classes from the matplotlib.ticker module.
import matplotlib.pyplot as plt import matplotlib.ticker as tck import numpy as np # Create Plot f,ax=plt.subplots(figsize=(7,4)) # Sample Data x=np.arange(-10.0,10.0,0.1) y=np.arctan(x) # Plot the data ax.plot(x/np.pi,y) # Customizing y-axis Ticks ax.yaxis.set_major_formatter(tck.FormatStrFormatter('%g $\pi$')) ax.yaxis.set_major_locator(tck.MultipleLocator(base=0.5)) plt.grid() plt.show()
Output
On executing the above code we will get the following output −
Custom Package for Radian Ticks
A custom package named "basic_units.py" can denote the tick marks using the radians. This package is not part of the standard or widely recognized packages and needs to be downloaded separately(available in the examples folder of Matplotlib).
Example
This example demonstrates how to create a plot with radians using the basic_units mockup example package.
import matplotlib.pyplot as plt from basic_units import radians import numpy as np # Create Plot f,ax=plt.subplots(figsize=(7,4)) x = np.arange(-10.0,10.0,0.1) y = list(map(lambda y: y*radians,np.arctan(x))) x = list(map(lambda x: x*radians,x)) ax.plot(x,y,'b.') plt.xlabel('radians') plt.ylabel('radians') plt.show()
Output
On executing the above code we will get the following output −