在此之后,我成功地按照我想要的方式旋转标签。
axes = pd.plotting.scatter_matrix(df_plot, alpha=0.1, figsize=[10, 10])
n = len(df_plot.columns) - 1
for x in range(n):
for y in range(n):
# to get the axis of subplots
ax = axes[x, y]
# to make x axis name vertical
ax.xaxis.label.set_rotation(90)
# to make y axis name horizontal
ax.yaxis.label.set_rotation(0)
# to make sure y axis names are outside the plot area
ax.yaxis.labelpad = 25
Run Code Online (Sandbox Code Playgroud)
现在的问题是(1)我需要手动调整标签板(这不是一个选项,因为我有许多从循环创建的此类图)和(2)较长的标签被图形边缘截断(这可以通过 plt.tight_layout() 部分解决,但这也增加了我不想要的散点图之间的空间)。我怎样才能解决这个问题?我想一定有简单的“自动调整”?
我使用以下代码创建一个pandas scatter-matrix:
import numpy as np
import pandas as pd
a = np.random.normal(1, 3, 100)
b = np.random.normal(3, 1, 100)
c = np.random.normal(2, 2, 100)
df = pd.DataFrame({'A':a,'B':b,'C':c})
pd.scatter_matrix(df, diagonal='kde')
Run Code Online (Sandbox Code Playgroud)
这导致以下散布矩阵:
第一行没有ytick标签,第3行没有xtick标签,第3项"C"没有标记.
知道如何用缺少的标签完成这个情节吗?