Single and Multiple Colors
Single Color Application
Basic Single Color Bar Chart
import matplotlib.pyplot as plt
## Single color for entire bar chart
plt.figure(figsize=(8, 4))
plt.bar(['A', 'B', 'C'], [10, 20, 15], color='blue')
plt.title('Single Color Bar Chart')
plt.show()
Multiple Color Strategies
Individual Bar Colors
## Different color for each bar
plt.bar(['A', 'B', 'C'],
[10, 20, 15],
color=['red', 'green', 'blue'])
Color List and Arrays
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1']
plt.bar(['A', 'B', 'C'], [10, 20, 15], color=colors)
Advanced Color Mapping
graph LR
A[Color Mapping] --> B[Uniform Colors]
A --> C[Gradient Colors]
A --> D[Conditional Colors]
Gradient Color Mapping
import numpy as np
data = [10, 20, 15]
colors = plt.cm.viridis(np.linspace(0, 1, len(data)))
plt.bar(['A', 'B', 'C'], data, color=colors)
Color Selection Techniques
Technique |
Description |
Example |
Uniform Colors |
Same color for all bars |
color='blue' |
Individual Colors |
Unique color per bar |
color=['red','green','blue'] |
Gradient Colors |
Colors based on value |
plt.cm.viridis() |
Conditional Coloring
def get_color(value):
return 'green' if value > 15 else 'red'
colors = [get_color(val) for val in [10, 20, 15]]
plt.bar(['A', 'B', 'C'], [10, 20, 15], color=colors)
LabEx Visualization Insight
When working with multiple colors, LabEx recommends maintaining visual clarity and ensuring color choices enhance data interpretation.