我有以下情节:
我想通过将刻度旋转约40度,使x轴刻度更可读。所以来自:
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()