如何在熊猫箱图中更改y-label步骤

我只是想更改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选项。我在做什么错了?

yufen0312 回答:如何在熊猫箱图中更改y-label步骤

使用ax.set_yticks(np.arange(min,max,step))plt.yticks(np.arange(min,step))
ax.grid(True)打开网格。

您是否正在寻找类似的东西?

import pandas as pd,numpy as np
import matplotlib.pyplot as plt
import seaborn as sns;sns.set()

from numpy import arange

data = np.random.randint(0,40,size=40)
fig = plt.figure(1,figsize=(20,30))
ax = fig.add_subplot(111)
ax.boxplot(data)  

ax.set_yticks(np.arange(0,1.0))
ax.grid(True)
plt.show()  

enter image description here

本文链接:https://www.f2er.com/3082083.html

大家都在问