Не могу установить разные цвета для каждого столбца, когда я помещаю его поверх кластерной диаграммы - PullRequest
0 голосов
/ 29 сентября 2018

Вот мой пример, я не могу определить разные цвета полос ... по какой-то причине все красные.That's what I get

import pandas as pd 
import seaborn as sns 
import matplotlib.pyplot as plt  
# initiliaze a dataframe with index and column names 
idf = pd.DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6]), ('C', 10, 
20, 30]), ('D', [14, 15, 16])], orient='index', columns=['x', > 'y', 'z'])
# Plot the clustermap which will be a figure by itself 
cax = sns.clustermap(idf, col_cluster=False, row_cluster=True)

# Get the column dendrogram axis 
cax_col_dend_ax = cax.ax_col_dendrogram.axes
# Plot the boxplot on the column dendrogram axis
idf.iloc[0,:].plot(kind='bar', ax=cax_col_dend_ax, color = ['r', 'g', 'b'])

# Show the plot 
plt.show()

1 Ответ

0 голосов
/ 29 сентября 2018

Ваш код отлично работает для меня.Кажется, вы используете старую версию Python, потому что я получил FutureWarning: from_items is deprecated..Хотя это из pandas, но вы можете обновить.Тем не менее, вы все равно можете изменить цвета следующим образом

import matplotlib as mpl

# Your code here
ax1 = idf.iloc[0,:].plot.bar(ax=cax_col_dend_ax)
colors = ['r', 'g', 'b']
bars = [r for r in ax1.get_children() if isinstance(r, mpl.patches.Rectangle)]

for i, bar in enumerate(bars[0:3]):
    bar.set_color(colors[i])

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...