Bird
0
0

Which of the following is the correct way to apply the 'viridis' colormap to an image using matplotlib?

easy📝 Syntax Q12 of 15
Matplotlib - Image Display
Which of the following is the correct way to apply the 'viridis' colormap to an image using matplotlib?
Aplt.imshow(image, color='viridis')
Bplt.imshow(image, cmap='viridis')
Cplt.imshow(image, cmap=viridis)
Dplt.imshow(image, colormap='viridis')
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct parameter name for colormap

    The parameter to set colormap in plt.imshow() is cmap, and it expects a string name.
  2. Step 2: Check the syntax for passing the colormap

    Passing cmap='viridis' is correct. Using color or colormap is incorrect, and omitting quotes causes an error.
  3. Final Answer:

    plt.imshow(image, cmap='viridis') -> Option B
  4. Quick Check:

    Use cmap='name' syntax [OK]
Quick Trick: Use cmap='colormap_name' exactly [OK]
Common Mistakes:
  • Using color instead of cmap
  • Forgetting quotes around colormap name
  • Using colormap instead of cmap

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes