我只是想更改y轴上的标签以显示更多数字。例如,范围为0-40,则显示数字0、10、20、30、40。 我想看到0、1、2、3、4,... 38、39、40。 我也希望显示一个网格(辅助线或如何称呼它)。
我的代码如下所示,其中有一个数据框,其中包含火车数据集名称,分类器名称和时间。 我为每个分类器创建一个箱线图,显示该分类器在所有数据集上花费的时间。
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
## agg backend is used to create plot as a .png file
mpl.use('agg')
# read dataset
data = pd.read_csv("classifier_times_sml.csv",";")
# extract data
g = data.sort_values("time",ascending=False)[["classifier","train","time"]].groupby("classifier")
# Create a figure instance
fig = plt.figure(1,figsize=(20,30))
# Create an axes instance
ax = fig.add_subplot(111)
labels = []
times = []
counter = 0
for group,group_df in g:
# Create the boxplot
times.append( np.asarray(group_df["time"]) )
labels.append(group)
# Create the boxplot
bp = ax.boxplot(times,showfliers=False )
ax.set_xticklabels(labels,rotation=90)
# Save the figure
fig.savefig('times_sml.png',bbox_inches='tight')
我一直在进行彻底搜索,但没有找到关于箱线图的任何有用选项。这里不允许使用ax.boxplot(...)的grid选项。我在做什么错了?