my df is like this.
when i first draw like this,
weekend_data = seoul_moving[seoul_moving['์์ผ'].isin(['ํ ', '์ผ'])]
grouped_weekend = weekend_data.groupby('์์ผ')['๋์ฐฉ ์๊ตฐ๊ตฌ ์ฝ๋'].value_counts().unstack()
grouped_weekend.plot(kind='bar', stacked=True)
plt.title('์ฃผ๋ง ๋์ฐฉ ์๊ตฐ๊ตฌ๋ณ ์ ๋์ธ๊ตฌ ๋น์จ')
plt.xlabel('์์ผ')
plt.ylabel('์ ๋์ธ๊ตฌ๋น์จ')
plt.legend(title='๋์ฐฉ ์๊ตฐ๊ตฌ ์ฝ๋')
plt.show()
result is
(look color orderโฆ order is same with arrival code)
bar is stacked by arrival_code.
but i want to bar is stacked by value order.
so i draw with this code
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
weekend_data = seoul_moving2[seoul_moving2['weekday'].isin(['saturday', 'sunday'])]
grouped_weekend = weekend_data.groupby('weekday')['arrival_code'].value_counts().unstack()
a=grouped_weekend
fig, ax = plt.subplots()
x = a.index
indexes = np.argsort(a.values).T
heights = np.sort(a.values).T
order = -1
bottoms = heights[::order].cumsum(axis=0)
bottoms = np.insert(bottoms, 0, np.zeros(len(bottoms[0])), axis=0)
colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
'#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf',
'#aec7e8', '#ffbb78', '#98df8a', '#ff9896', '#c5b0d5',
'#c49c94', '#f7b6d2', '#c7c7c7', '#dbdb8d', '#9edae5',
'#393b79', '#637939', '#8c6d31', '#843c39', '#7b4173',
'#5254a3', '#637939', '#8c6d31', '#843c39', '#7b4173']
# ์์ ์ํ ์ค์
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=colors)
mpp_colors = dict(zip(a.columns, plt.rcParams['axes.prop_cycle'].by_key()['color']))
for btms, (idxs, vals) in enumerate(list(zip(indexes, heights))[::order]):
mps = np.take(np.array(a.columns), idxs)
ax.bar(x, height=vals, bottom=bottoms[btms], color=[mpp_colors[m] for m in mps])
#ax.set_ylim(bottom=0, top=2)
plt.legend((np.take(np.array(a.columns), np.argsort(a.values)[0]))[::order], loc='upper right')
then result is this
i success draw with plt.
but i want draw with this plotly.
maybe,
i can draw with plotly with similar way.
for iteration + several barchart.
is there any simple way draw with plotly???