Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Customize color stacked bar chart matplotlib

import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
from matplotlib.colors import LinearSegmentedColormap

matplotlib.style.use('ggplot')
from pandas import DataFrame

weather = ('Day', 'Freeze', 'Wind', 'Flood', 'Quake', 'Hail')
colors = sns.color_palette("cubehelix", n_colors=len(weather))
cmap1 = LinearSegmentedColormap.from_list("my_colormap", colors)

data1 = [["M", 66386, 174296, 75131, 577908, 32015],
         ["T", 58230, 381139, 78045, 99308, 160454],
         ["W", 89135, 80552, 152558, 497981, 603535],
         ["T", 78415, 81858, 150656, 193263, 69638],
         ["F", 139361, 331509, 343164, 781380, 52269]]


df = DataFrame(data=data1)
df.columns = weather
df = df.set_index('Day')
df.plot(kind='bar', stacked=True, colormap=cmap1)
plt.show()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Customize #color #stacked #bar #chart #matplotlib
ADD COMMENT
Topic
Name
2+6 =