0
0
Matplotlibdata~10 mins

Polar axes in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a polar plot using matplotlib.

Matplotlib
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A"3d"
B"polar"
C"rectilinear"
D"scatter"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '3d' projection instead of 'polar'.
Leaving the projection parameter empty.
Using 'scatter' which is not a projection type.
2fill in blank
medium

Complete the code to plot points on a polar axis with radius values.

Matplotlib
import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0, 2*np.pi, 100)
r = np.abs(np.sin(theta))

fig, ax = plt.subplots(subplot_kw={{'projection': 'polar'}})
ax.plot(theta, [1])
plt.show()
Drag options to blanks, or click blank then click option'
Anp.cos(theta)
Btheta
Cr
Dnp.linspace(0, 1, 100)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the angle array twice instead of radius.
Passing a cosine function instead of radius.
Passing a linear space unrelated to radius.
3fill in blank
hard

Fix the error in the code to correctly set the zero location of the polar plot.

Matplotlib
import matplotlib.pyplot as plt

fig, ax = plt.subplots(subplot_kw={{'projection': 'polar'}})
ax.set_theta_zero_location([1])
plt.show()
Drag options to blanks, or click blank then click option'
A90
B0
C'East'
D'N'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer instead of a string.
Using degrees like 90 instead of a direction string.
Using invalid strings like 'East' instead of 'E'.
4fill in blank
hard

Fill both blanks to create a scatter plot on polar axes with red points.

Matplotlib
import numpy as np
import matplotlib.pyplot as plt

angles = np.linspace(0, 2*np.pi, 50)
radii = np.random.rand(50)

fig, ax = plt.subplots(subplot_kw={{'projection': 'polar'}})
ax.scatter([1], [2], color='red')
plt.show()
Drag options to blanks, or click blank then click option'
Aangles
Bradii
Cnp.linspace(0, 1, 50)
Dnp.random.rand(50)
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping angles and radii in the scatter function.
Using unrelated arrays for angles or radii.
Forgetting to specify the projection as 'polar'.
5fill in blank
hard

Fill all three blanks to create a polar bar plot with blue bars and set the direction clockwise.

Matplotlib
import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0.0, 2 * np.pi, 8, endpoint=False)
radii = 10 * np.random.rand(8)
width = np.pi / 4 * np.random.rand(8)

fig, ax = plt.subplots(subplot_kw={{'projection': 'polar'}})
bars = ax.bar([1], [2], width=[3], color='blue', alpha=0.5)
ax.set_theta_direction(-1)
plt.show()
Drag options to blanks, or click blank then click option'
Atheta
Bradii
Cwidth
Dnp.linspace(0, 1, 8)
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of arguments in ax.bar.
Using unrelated arrays for any of the arguments.
Not setting the projection to 'polar'.