Customize Color Stacked Bar Chart Matplotlib

[Solved] Customize Color Stacked Bar Chart Matplotlib | Php - Code Explorer | yomemimo.com
Question : Customize color stacked bar chart matplotlib

Answered by : chunxiao-wang

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 : https://stackoverflow.com/questions/40960437/using-a-custom-color-palette-in-stacked-bar-chart | Last Update : Mon, 13 Jun 22

Answers related to customize color stacked bar chart matplotlib

Code Explorer Popular Question For Php