Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: python pickle module 
Python :: check if list is in ascending order python 
Python :: pandas fillna with none 
Python :: python binary 
Python :: dictionary changed size during iteration 
Python :: add timestamp csv python 
Python :: online python compiler 
Python :: isupper() in python 
Python :: messages in django 
Python :: python ceiling division 
Python :: if else pandas dataframe 
Python :: get first element of array python 
Python :: producer and consumer problem in python 
Python :: python keyboard hold key 
Python :: mysql store numpy array 
Python :: python module path 
Python :: how to import a class from a file to another python 
Python :: print to file python 
Python :: __mul__ 
Python :: requests sessions 
Python :: return dataframe as csv flask 
Python :: python relative import 
Python :: django form field add attrs 
Python :: k fold cross validation from scratch python 
Python :: python argparse argument without value 
Python :: lambda function if else in python 
Python :: python spread operator 
Python :: function with args* example 
Python :: python install graphviz and 
Python :: python string replace letters with numbers 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =