Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to plot half or quarter polar plots in Matplotlib?
To plot half or quarter polar plots in Matplotlib, we can control the angular range using the set_thetamax() and set_thetamin() methods. This allows us to create partial polar plots that show only specific angular segments.
Steps to Create Partial Polar Plots
Set the figure size and adjust the padding between and around the subplots.
Create a new figure or activate an existing figure using figure() method.
Add an axes to the figure as part of a subplot arrangement with
projection="polar".For half or quarter polar plots, use set_thetamax() method to limit the maximum angle.
Optionally use set_thetamin() to set the minimum angle.
To display the figure, use show() method.
Quarter Polar Plot Example
Here's how to create a quarter polar plot (90 degrees) ?
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection="polar") # Set maximum angle to 90 degrees for quarter plot max_theta = 90 ax.set_thetamax(max_theta) # Add some sample data theta = np.linspace(0, np.radians(90), 100) r = theta ax.plot(theta, r) plt.show()
Half Polar Plot Example
To create a half polar plot, set the maximum angle to 180 degrees ?
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection="polar") # Set maximum angle to 180 degrees for half plot ax.set_thetamax(180) # Add some sample data theta = np.linspace(0, np.radians(180), 100) r = np.sin(2 * theta) ax.plot(theta, r) plt.show()
Custom Angular Range
You can also create custom angular ranges by combining set_thetamin() and set_thetamax() ?
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection="polar") # Custom range from 45 to 135 degrees ax.set_thetamin(45) ax.set_thetamax(135) # Add some sample data theta = np.linspace(np.radians(45), np.radians(135), 100) r = np.ones_like(theta) ax.plot(theta, r) plt.show()
Common Angular Ranges
| Plot Type | Angle Range | Method |
|---|---|---|
| Quarter Plot | 0° to 90° | set_thetamax(90) |
| Half Plot | 0° to 180° | set_thetamax(180) |
| Three-Quarter Plot | 0° to 270° | set_thetamax(270) |
| Custom Range | 45° to 135° |
set_thetamin(45) + set_thetamax(135)
|
Conclusion
Use set_thetamax() to create quarter, half, or custom polar plots by limiting the angular range. Combine with set_thetamin() for precise control over the displayed angular segment.
