Concept Flow - Named colors and hex codes
Start
Choose color type
Named
Use color in plot
Display plot
End
This flow shows choosing a color by name or hex code, using it in a plot, and displaying the result.
import matplotlib.pyplot as plt plt.plot([1,2,3], color='red') plt.plot([3,2,1], color='#00FF00') plt.show()
| Step | Action | Color Input | Color Used | Plot Element |
|---|---|---|---|---|
| 1 | Plot first line | 'red' | Red (RGB: 1,0,0) | Line 1 in red |
| 2 | Plot second line | '#00FF00' | Green (RGB: 0,1,0) | Line 2 in green |
| 3 | Show plot | N/A | N/A | Plot displayed with two colored lines |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| color | None | 'red' | '#00FF00' | N/A |
| line_colors | [] | ['red'] | ['red', '#00FF00'] | ['red', '#00FF00'] |
Named colors and hex codes in matplotlib: - Use named colors like 'red', 'blue', 'green'. - Use hex codes like '#FF0000' for red. - Both specify colors for plot elements. - Hex codes are #RRGGBB format. - Matplotlib accepts both interchangeably.