Plot a polar color wheel based on a colormap using Python/Matplotlib

To create a polar color wheel based on a colormap using Python/Matplotlib, we use the ColorbarBase class with polar projection. This creates a circular representation of colors from the chosen colormap.

Steps

  • 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 using add_axes() method with polar projection.

  • Set the direction of the axes to cover full circle (2?).

  • Linearly normalize the data using Normalize class.

  • Draw a colorbar in the existing polar axes.

  • Set the artist's visibility and turn off axis labels.

  • To display the figure, use show() method.

Example

Here's how to create a polar color wheel using the copper colormap ?

import numpy as np
from matplotlib import pyplot as plt, cm, colors, colorbar

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig = plt.figure()
display_axes = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar')
display_axes._direction = 2 * np.pi

norm = colors.Normalize(0.0, 2 * np.pi)
cb = colorbar.ColorbarBase(display_axes, cmap=cm.get_cmap('copper', 2056), 
                          norm=norm, orientation='horizontal')

cb.outline.set_visible(False)
display_axes.set_axis_off()

plt.show()

Using Different Colormaps

You can create color wheels with various colormaps like 'hsv', 'rainbow', or 'viridis' ?

import numpy as np
from matplotlib import pyplot as plt, cm, colors, colorbar

# Create figure with multiple subplots
fig, axes = plt.subplots(1, 3, figsize=(15, 5), subplot_kw=dict(projection='polar'))

colormaps = ['hsv', 'rainbow', 'viridis']

for i, cmap_name in enumerate(colormaps):
    ax = axes[i]
    ax._direction = 2 * np.pi
    
    norm = colors.Normalize(0.0, 2 * np.pi)
    cb = colorbar.ColorbarBase(ax, cmap=cm.get_cmap(cmap_name, 256), 
                              norm=norm, orientation='horizontal')
    
    cb.outline.set_visible(False)
    ax.set_axis_off()
    ax.set_title(cmap_name.capitalize(), pad=20)

plt.tight_layout()
plt.show()

Key Parameters

Parameter Purpose Example Value
projection='polar' Creates circular axes 'polar'
_direction Sets angular range 2 * np.pi
cmap Colormap to use 'copper', 'hsv'
norm Normalizes color range colors.Normalize(0, 2?)

Conclusion

Creating polar color wheels in Matplotlib involves using polar projection with ColorbarBase. This technique is useful for visualizing cyclic data or creating attractive color displays for design applications.

Updated on: 2026-03-25T21:22:31+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements