Syntax error Plot scatter points on polar axis in Matplotlib

Plot scatter points on polar axis in Matplotlib



To plot scatter points on polar axis in Matplotlib, we can take the following steps −

  • Set the figure size and adjust the padding between and around the subplots.
  • Initialize a variable, N, for number of sample data.
  • Get r, theta, area and color data using numpy
  • Create a new figure or activate an existing figure.
  • Plot theta, r, colors and area, using scatter() method.
  • To display the figure, use show() method.

Example

import numpy as np
import matplotlib.pyplot as plt

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

N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

plt.show()

Output

Updated on: 2021-06-15T13:15:37+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements