range(len(df.columns))
从零开始,而盒形图文档默认使用range(1,N+1)
。如IOBE所指出的那样,您可以在range
的开头加1并增加上限以保留相同数量的列以显示。您还可以通过使用positions
kwarg在绘图时直接指定ticks。df = df[["Col1", "Col2", "Col3", "Col4", "Col5", "Col6", "Col7"]]
df.plot.box()
plt.xticks(list(range(1,len(df.columns)+1)), df.columns, rotation='vertical')
plt.tight_layout()
plt.show()
range(1, len(df.columns)+1)
- ImportanceOfBeingErnest