python xticks旋转后发生错位_旋转Matplotlib记号标签会导致奇怪的间距问题

我有以下情节:

我想通过将刻度旋转约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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值