私は1年365日をいくつかのクラスタに割り当てました。私はヒートマップ上にそれらをプロットしようとしています。Matplotlib:cbar.set_xticklabelsは効果がありません
私のコードはcbar.set_ticks(some_rangeは)何も影響していることを除いて正常に動作します:右のテキストが、誤った位置
はここでMCVE
from datetime import date
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
import matplotlib
import seaborn as sns
#create some random data
n_cluster = 4
index = pd.date_range('01/01/2016', end='31/12/2016', freq='1D')
df = pd.DataFrame(np.random.randint(0, n_cluster, len(index)),
index=index, columns=['cluster'])
pivot = df.pivot_table('cluster',
columns=[lambda x: x.weekofyear],
index= [lambda x: x.dayofweek])
#yticklabels of the heatmap
days = [date(2018, 1, d).strftime('%a')[:3] for d in range(1, 8)]
#get a discrete cmap
cmap = plt.cm.get_cmap('RdBu', n_cluster)
fig = plt.figure(figsize=(10,3))
gs = matplotlib.gridspec.GridSpec(1, 2, width_ratios=[50,1])
ax = plt.subplot(gs[0])
cbar = plt.subplot(gs[1])
sns.heatmap(pivot, square=True, cmap=cmap,
yticklabels=days, ax=ax, cbar_ax=cbar)
#There is something wrong here
cbar.set_yticks([i + 1/(2.0*n_cluster) for i in np.arange(0, 1, 1.0/n_cluster)])
#This one is ok
cbar.set_yticklabels(range(0, n_cluster))
私のカラーバー上の目盛りラベルをされていません回避策として、あなたの助け
はどこに目盛りラベルになりたいですか? – kazemakase
ダークブルーのパッチの中央に立っているカラーパッチ、たとえば「3」に合わせることをお勧めします。カラーバーの全高さの '[0.125,0.375,0.625,0.875] 'に対応しています。 – jodoox
海賊のように見えますが、何とかティックポジションを強制します。将来、 'cbar_kws'引数でカラーバーの目盛りを設定することは可能かもしれませんが、これは現在' ticks'([see here](https://github.com/mwaskom/seaborn/)問題/ 459))。 – kazemakase