我有以下情節:旋轉Matplotlib刻度標記導致奇怪的間隔發出
我想使x軸蜱通過〜40度旋轉蜱更具有可讀性。所以從:
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)
當我這樣做,不過,我得到一些瘋狂的間距問題:
(忽略的變化在顏色...)
導致此問題的原因是什麼?我該如何解決它?下面是一個最小工作示例:
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()
圖像顯示不正確,似乎也沒有顏色變化... –