Python 使用pyplot调整子地块

Python 使用pyplot调整子地块,python,matplotlib,plot,subplot,Python,Matplotlib,Plot,Subplot,我对pyplot子地块有一个小问题。我想把7个图放在同一个图上(见下文),我希望我的图在X轴上看起来更方,分布更少。用更合适的Y轴和X轴获得较少覆盖图形的解决方案? 我会给你我用来得到结果的代码 谢谢你的帮助 # Max depth plt.subplot(421) x_max_depth = np.arange(0, 55, 5) y_max_depth = [0.734008866371121, 0.8611695414387883, 0.848421052631579, 0.861

我对pyplot子地块有一个小问题。我想把7个图放在同一个图上(见下文),我希望我的图在X轴上看起来更方,分布更少。用更合适的Y轴和X轴获得较少覆盖图形的解决方案? 我会给你我用来得到结果的代码

谢谢你的帮助

    # Max depth
plt.subplot(421)
x_max_depth = np.arange(0, 55, 5)
y_max_depth = [0.734008866371121, 0.8611695414387883, 0.848421052631579, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737]
plt.plot(x_max_depth, y_max_depth, marker='.', color='b', linewidth=1.5)
plt.title('Max depth', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for a_max_depth,b_max_depth in zip(x_max_depth, y_max_depth): 
    plt.text(a_max_depth, b_max_depth, str(np.round(b_max_depth,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0.73, 0.87, 0.01), fontname='Calibri', fontsize=9)

# Max features
plt.subplot(422)
x_max_features = ['0', '5', '10', '15', '20', '26', 'log2', 'auto', 'sqrt']
y_max_features = [0.8613736609955891, 0.8610818774994737, 0.8484848484848485, 0.8484848484848485, 0.8738170347003155, 0.8359966358284273, 0.8611695414387883, 0.8610818774994737, 0.8610818774994737]
plt.plot(x_max_features, y_max_features, marker='.', color='b', linewidth=1.5)
plt.title('Max features', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for x,y in zip(x_max_features, y_max_features): 
    plt.text(x, y, str(np.round(y,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0.83, 0.88, 0.01), fontname='Calibri', fontsize=9)
plt.xticks(['0','5','10','15','20','26','log2','auto','sqrt'], fontname='Calibri', fontsize=9)

# Max leaf nodes
plt.subplot(423)
x_max_leaf_nodes = np.arange(0, 225, 25)
y_max_leaf_nodes = [0.734008866371121, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737]
plt.plot(x_max_leaf_nodes, y_max_leaf_nodes, marker='.', color='b', linewidth=1.5)
plt.title('Max leaf nodes', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for a_max_leaf_nodes,b_max_leaf_nodes in zip(x_max_leaf_nodes, y_max_leaf_nodes):
    plt.text(a_max_leaf_nodes, b_max_leaf_nodes, str(np.round(b_max_leaf_nodes,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0.73, 0.87, 0.01), fontname='Calibri', fontsize=9)
plt.xticks(np.arange(0, 225, 25), fontname='Calibri', fontsize=9)

# Max samples
plt.subplot(424)
x_max_samples = np.arange(0, 1.1, 0.1)
y_max_samples = [0, 0.8613154023954612, 0.8610818774994737, 0.8738965952080706, 0.8738965952080706, 0.8738965952080706, 0.8738965952080706, 0.8738965952080706, 0.8738965952080706, 0.8738965952080706, 0]
plt.plot(x_max_samples, y_max_samples, marker='.', color='b', linewidth=1.5)
plt.title('Max samples', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for a_max_samples,b_max_samples in zip(x_max_samples, y_max_samples): 
    plt.text(a_max_samples, b_max_samples, str(np.round(b_max_samples,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0, 1, 0.1), fontname='Calibri', fontsize=9)
plt.xticks(np.arange(0, 1.2, 0.2), fontname='Calibri', fontsize=9)

# Min samples leaf
plt.subplot(425)
x_min_samples_leaf = np.arange(0, 55, 5)
y_min_samples_leaf = [0.8610818774994737, 0.848421052631579, 0.8228969006957622, 0.7842183202877089, 0.7842183202877089, 0.7842183202877089, 0.758832240321557, 0.7591888466413181, 0.7591888466413181, 0.7591888466413181, 0.7591888466413181]
plt.plot(x_min_samples_leaf, y_min_samples_leaf, marker='.', color='b', linewidth=1.5)
plt.title('Min samples leaf', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for a_min_samples_leaf,b_min_samples_leaf in zip(x_min_samples_leaf, y_min_samples_leaf): 
    plt.text(a_min_samples_leaf, b_min_samples_leaf, str(np.round(b_min_samples_leaf,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0.75, 0.87, 0.01), fontname='Calibri', fontsize=9)
plt.xticks(np.arange(0, 55, 5), fontname='Calibri', fontsize=9)

# Min samples split
plt.subplot(426)
x_min_samples_split = np.arange(0, 55, 5)
y_min_samples_split = [0, 0.8610818774994737, 0.8610818774994737, 0.8483252580577206, 0.8355471220746363, 0.8483252580577206, 0.8483252580577206, 0.8483252580577206, 0.8481973434535104, 0.8227100042211903, 0.8227100042211903]
plt.plot(x_min_samples_split, y_min_samples_split, marker='.', color='b', linewidth=1.5)
plt.title('Min samples split', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for a_min_samples_split,b_min_samples_split in zip(x_min_samples_split, y_min_samples_split): 
    plt.text(a_min_samples_split, b_min_samples_split, str(np.round(b_min_samples_split,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0, 1, 0.1), fontname='Calibri', fontsize=9)
plt.xticks(np.arange(0, 55, 5), fontname='Calibri', fontsize=9)

# N estimator
plt.subplot(427)
x_estimator = np.array([0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000])
y_estimator = np.array([0.7866555113992888, 0.8612279226240538, 0.8612279226240538, 0.8612279226240538, 0.8612279226240538, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737, 0.8610818774994737])
plt.plot(x_estimator, y_estimator, marker='.', color='b', linewidth=1.5)
plt.title('Number of estimator trees', Subtitle) 
plt.xlabel('Parameter value', Axis) 
plt.ylabel('Kappa score', Axis) 
for a_estimator,b_estimator in zip(x_estimator, y_estimator): 
    plt.text(a_estimator, b_estimator, str(np.round(b_estimator,3)), fontname='Calibri', fontsize=8)
plt.yticks(np.arange(0.78, 0.88, 0.01), fontname='Calibri', fontsize=9)
plt.xticks(np.arange(0, 1100, 100), fontname='Calibri', fontsize=9)

plt.tight_layout()
plt.suptitle('Random Forest parameters', fontname='Calibri', fontsize=18)
plt.show()
下面是通过运行提供的代码获得的子批。我们可以在X轴和Y轴上看到一些不合适的图形: