Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a colorbar to the plot.
Matplotlib
import matplotlib.pyplot as plt import numpy as np img = np.random.rand(10,10) plt.imshow(img) plt.colorbar(orientation=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using location parameter instead of orientation
Setting orientation to horizontal when vertical is default
✗ Incorrect
The default colorbar orientation is vertical, so specifying orientation='vertical' correctly adds a vertical colorbar.
2fill in blank
mediumComplete the code to place the colorbar on the right side of the plot.
Matplotlib
import matplotlib.pyplot as plt import numpy as np img = np.random.rand(10,10) plt.imshow(img) plt.colorbar(orientation=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using location='right' instead of orientation='vertical'
Setting orientation to horizontal which places colorbar at bottom
✗ Incorrect
The default orientation is vertical, which places the colorbar on the right side by default.
3fill in blank
hardFix the error in the code to correctly position the colorbar below the plot.
Matplotlib
import matplotlib.pyplot as plt import numpy as np img = np.random.rand(10,10) plt.imshow(img) plt.colorbar(orientation=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bottom' which is not a valid orientation value
Using 'vertical' which places colorbar on the side
✗ Incorrect
To place the colorbar below the plot, orientation must be set to 'horizontal'.
4fill in blank
hardFill both blanks to create a horizontal colorbar below the plot with a label.
Matplotlib
import matplotlib.pyplot as plt import numpy as np img = np.random.rand(10,10) im = plt.imshow(img) cbar = plt.colorbar(im, orientation=[1], [2]='bottom') cbar.set_label('Intensity') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using vertical orientation with bottom location
Using label parameter instead of location
✗ Incorrect
orientation='horizontal' places the colorbar below, and location='bottom' explicitly sets its position.
5fill in blank
hardFill all three blanks to create a vertical colorbar on the left side with a label and shrink it.
Matplotlib
import matplotlib.pyplot as plt import numpy as np img = np.random.rand(10,10) im = plt.imshow(img) cbar = plt.colorbar(im, orientation=[1], [2]='left', shrink=[3]) cbar.set_label('Value') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using horizontal orientation with left location
Not using shrink parameter correctly
Using label instead of location
✗ Incorrect
orientation='vertical' places the colorbar vertically, location='left' puts it on the left side, and shrink=0.5 reduces its size.