Альтернативным решением было бы разместить подзаговоры вручную в вашей фигуре, чтобы обеспечить максимальную гибкость в дизайне макета. Я собрал код, который показывает, как это можно сделать. Обратите внимание, что есть большая часть кода, который должен только визуально отображать формат xticks.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.close('all')
#------------------------------------------------------------- prepare data ----
randn = np.random.randn
train= df = pd.DataFrame(randn(10, 34))
ngraphs = train.shape[1]
#------------------------------------------------------------ create figure ----
fwidth = 15
fheight = 12
fig = plt.figure(figsize=(fwidth, fheight))
fig.patch.set_facecolor('white')
left_margin = 0.5/fwidth
right_margin = 0.5/fwidth
bottom_margin = 0.5/fheight
top_margin = 0.75/fheight
vinter_margin = 0.75/fheight
hinter_margin = 0.5/fwidth
#-------------------------------------------------------------- create axes ----
ncol = 6
nrow = int(np.ceil(ngraphs/float(ncol)))
w0 = (1 - (left_margin + right_margin + (ncol-1) * hinter_margin))/ncol
h0 = (1 - (bottom_margin + top_margin + (nrow-1) * vinter_margin))/nrow
AX0 = [0] * ngraphs
itot = 0
y0 = 1 - top_margin - h0
for row in range(nrow):
x0 = left_margin
for col in range(ncol):
AX0[itot] = fig.add_axes([x0, y0, w0, h0], frameon=True)
#-------------------------------------------------------- plot data ----
vals = np.size(train.iloc[:, itot].unique())
if vals < 10:
bins = vals
else:
vals = 10
AX0[itot].hist(train.iloc[:, itot], bins=30, color='#3F5D7D')
#--------------------------------------------------------- set axis ----
AX0[itot].axes.get_yaxis().set_visible(False)
AX0[itot].set_title(train.columns.values[itot])
#---- major ticks ----
AX0[itot].tick_params(top='off', labeltop='off')
AX0[itot].tick_params(axis='x', direction='out', labelsize=8)
trainmax = np.ceil(np.max(train.iloc[:, itot])/0.5)*0.5
trainmin = np.floor(np.min(train.iloc[:, itot])/0.5)*0.5
AX0[itot].set_xticks([trainmin,0, trainmax])
#---- minor ticks ----
AX0[itot].set_xticks(np.arange(trainmin, trainmax, 0.5), minor=True)
AX0[itot].tick_params(axis='x', which='minor', direction='out',
top='off', length=3)
#---- axis limits ----
AX0[itot].axis(xmin=trainmin, xmax=trainmax)
#---------------------------------------------------------- iterate ----
x0 = x0 + w0 + hinter_margin
itot += 1
if itot == ngraphs:
break
y0 = y0 - h0 - vinter_margin
plt.show(block=False)
fig.savefig('subplot_layout.png')
Какие результаты в:
Пожалуйста, скопируйте код, чем только разместить ссылку –