我正在尝试制作一个共享的y轴图(连续3个图)。 当我尝试为所有三个子图设置刻度宽度时,以下方法不起作用。
首先,我尝试通过rc params设置刻度线宽度。这适用于刻度长度,但不适用于宽度。我收到以下错误消息:
KeyError: 'xtick.major.width is not a valid rc parameter.See rcParams.keys() for a list of valid parameters.'
查看列表时xtick.major.width是一个有效的参数,那么还有什么可能是错的?
这里是代码
import matplotlib.pyplot as plt
import matplotlib as mpl
import scipy.io
from mpl_toolkits.axes_grid1 import Grid
import numpy as np
from pylab import *
# set tick width
mpl.rcParams['xtick.major.size'] = 10
mpl.rcParams['ytick.major.size'] = 10
mpl.rcParams['xtick.major.width'] = 2
#ignore all the data import please
X = scipy.io.loadmat('Ud04.mat')
psi11_final=X['psi11_final']
psi12_final=X['psi12_final']
psi21_final=X['psi21_final']
psi22_final=X['psi22_final']
psi11_final=flipud(psi11_final)
psi12_final=flipud(psi12_final)
psi21_final=flipud(psi21_final)
psi22_final=flipud(psi22_final)
na11_final=X['na11_final']
na12_final=X['na12_final']
na21_final=X['na21_final']
na22_final=X['na22_final']
na11_final=flipud(na11_final)
na12_final=flipud(na12_final)
na21_final=flipud(na21_final)
na22_final=flipud(na22_final)
np11_final=X['np11_final']
np12_final=X['np12_final']
np21_final=X['np21_final']
np22_final=X['np22_final']
np11_final=flipud(np11_final)
np12_final=flipud(np12_final)
np21_final=flipud(np21_final)
np22_final=flipud(np22_final)
extot=na11_final+na12_final+na21_final+na22_final+np11_final+np12_final+np21_final+np22_final
k_bar=X['k_bar']
nkap_bar=X['nkap_bar']
nkap_bar=nkap_bar[0,0]
kapmin=k_bar[0,0]
kapmax=k_bar[0,nkap_bar-1]
mu_bar=X['mu_bar']
nmu_bar=X['nmu_bar']
nmu_bar=nmu_bar[0,0]
mumin=mu_bar[0,0]
mumax=mu_bar[0,nmu_bar-1]
fig = plt.figure(1, (12., 4.))
grid = Grid(fig, 111, # similar to subplot(111)
nrows_ncols = (1,3), # creates 3x1 grid of axes
axes_pad=0.1) # pad between axes in inch.
for i in range(3):
#grid[i].imshow(extot,interpolation='nearest')
grid[i].imshow(extot,aspect='auto',extent=(kapmin,kapmax,mumin,mumax),interpolation='nearest')
plt.show()
然后我尝试通过在代码的最后几行进行以下更改并在开头删除rc参数来设置刻度线宽度:
ax = plt.gca()
ax.tick_params(axis='both',width=5)
for i in range(3):
#grid[i].imshow(extot,interpolation='nearest')
grid[i].imshow(extot,aspect='auto',extent=(kapmin,kapmax,mumin,mumax),interpolation='nearest')
plt.show()
这仅改变了3 * 1系列中最后一个图的刻度厚度。有没有办法在不使用rc参数的情况下访问所有这些?摆脱刻度标签的重叠也是有帮助的。在那里,我试图用
手动设置滴答#plt.xticks([0.02,0.04,0.06], [0.02,0.04,0.06])
#plt.yticks([-0.3,-1.2,-1.1,-1.0], [-0.3,-1.2,-1.1,-1.0])
但它再次改变了网格中3个图中最后一个的外观。