2016-03-27 26 views
0

sorunları neden olur. Yani gelen:garip aralık aşağıdaki arsa var

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

için:

enter image description here

(değişim yok saymak: Bunu yaptığınızda

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

olsa da, bazı çılgın aralık sorunlarını olsun renkli ...)

Bu sorun neden oluyor? Bunu nasıl düzeltebilirim? İşte en az bir örnek:

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

Resimler doğru şekilde görüntülenmiyor ve renk değişikliği yok gibi görünüyor ... –

cevap

1

Xticklabels aynı uzunlukta ise, bu tür bir sorun olmaz. Ancak farklı uzunluktaki etiketler verildiğinde, bu tür bir problemle karşılaşabilirsiniz. Çünkü varsayılan döndürme, xlabel dizesinin ortasından. Böylece, döndürme istasyonunu ['right', 'center', 'left'] öğesinden doğru şekilde ayarlamayı deneyebilirsiniz.

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

Bu işe yaradı - teşekkürler! Görünüşe göre 'Sol' doğru ayardır - 'sağ' daha da fazla sorun yaratır. Rotasyon yönünün nedenini tahmin ediyorum. –