2016-03-27 12 views
0

を出す原因となります。だから、から:は奇妙な間隔が、私は次のプロットを持って

plt.xticks(list(range(0, width)), list(df_100.columns), rotation='90', fontsize=16)

へ:私はこれを行うと

plt.xticks(list(range(0, width)), list(df_100.columns), rotation='40', fontsize=16)

、しかし、私はいくつかのクレイジー間隔の問題を得る:

enter image description here

(変更を無視しますカラーで...)

この問題の原因は何ですか?どうすれば修正できますか?

import matplotlib.pyplot as plt 
import numpy as np 

# Z is your data set 
N = 100 
height = df_100.shape[0] 
width = df_100.shape[1] 
# Z = np.random.random((100, 29)) 

# G is a NxNx3 matrix 
G = np.zeros((height,width,3)) 

# Where we set the RGB for each pixel 
G[Z>0.5] = [1, 1, 1] 
G[Z<0.5] = [0.25, 0.25, 0.25] 

fig, ax = plt.subplots(figsize=(20, 10)) 
ax.imshow(G, interpolation='none') 

ax.set_aspect('auto') 
ax.grid(None) 
ax.xaxis.tick_top() 
plt.xticks(list(range(0, width)), list(df_100.columns), rotation='45', fontsize=16) 
plt.yticks([0, df_100.shape[0] - 1], [1, df_100.shape[0]], fontsize=20) 
plt.tight_layout() 
plt.show() 
+0

画像が正しく表示されず、色が変わっていないようです... –

答えて

1

xticklabelsの長さが同じ場合、この種の問題は発生しません。しかし、ラベルの長さが異なると、この種の問題に遭遇する可能性があります。デフォルトの回転はxlabel文字列の中心からのものです。したがって、回転アンカーを ['right'、 'center'、 'left']から正しく設定することができます。

ha = 'left' # or 'right'. Experiment with it. 
ax.set_xticks(x) # set tick location 
ax.set_xticklabels(xlabels, rotation=40, ha=ha) # rotate the labels with proper anchoring. 
+0

これはうまくいきました---ありがとうございました! 「左」が適切な設定であるように見えます。「右」はさらに多くの問題を引き起こします。私は回転の方向を推測しているのはその理由です。 –

関連する問題