Complete the code to set the line color to a named color 'red' in matplotlib.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6], color='[1]') plt.show()
The color parameter accepts named colors like 'red'. Here, 'red' sets the line color to red.
Complete the code to set the marker color using a hex code for green.
import matplotlib.pyplot as plt plt.scatter([1, 2, 3], [4, 5, 6], marker='o', color='[1]') plt.show()
The hex code '#00FF00' represents green color. Using it sets the marker color to green.
Fix the error in the code by choosing the correct color format for a blue line.
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1], color=[1]) plt.show()
The color value must be a string. '#0000FF' is the hex code for blue, so it must be inside quotes.
Fill both blanks to create a dictionary mapping color names to their hex codes.
colors = {'red': '[1]', 'green': '[2]'}Hex codes for red and green are '#FF0000' and '#00FF00' respectively. They must be strings.
Fill all three blanks to create a dictionary comprehension that maps color names to their uppercase hex codes if the hex code starts with '#'.
colors = {'red': '#ff0000', 'blue': '#0000ff', 'green': '00ff00'}
result = {k: v[1]() for k, v in colors.items() if v[2]('#')}
print(result) # Output: [3]The comprehension converts hex codes to uppercase using .upper() if the string startswith '#'. The output dictionary includes only those keys.